欢迎光临
我们一直在努力

Oracle中图片的存贮与显示例程-PHP教程,PHP应用

建站超值云服务器,限时71元/月

//store.php
<html>
<head><title>store binary data into oracle database</title></head>
<body>

<?php
// 如果提交了表单,代码将被执行:
dl("php_oci8.dll");
$conn = ocilogon("scott","tiger");
if ($submit) {

echo "file name: <b>$userfile_name</b><br>\n";
echo "file size: <b>$userfile_size</b><br>\n";

$hwsize = getimagesize($userfile );
$w = $hwsize[0];
$h = $hwsize[1];
echo "image width: <b>$w</b><br>\n";
echo "image height: <b>$h</b><br>\n";

$imgtype = strtolower(substr( strrchr( $userfile_name, "." ), 1 ) );
if ($imgtype == "jpg")
  $imgtype = "jpeg";
echo "image type: <b>$imgtype</b><br>\n";

echo "created date; <b>".date(y-m-d)."</b><br>\n";

$sql = "insert into
picture (picid, username, width, height, imgsize, imgtype, created, image, filename, description)
values(picturepicid.nextval, $username, $w, $h, $userfile_size, $imgtype, to_date(".date(y-m-d).",yyyy-mm-dd), empty_blob(), $userfile_name, $description)
returning image into :image";

echo "<pre>$sql</pre>";
$stmt = ociparse($conn, $sql );

$image = ocinewdescriptor($conn );

ocibindbyname($stmt, ":image", $image, -1, sqlt_blob );

if (!ociexecute($stmt, oci_default)) {
  echo "execution failed";
  exit(1);
}

$fp = fopen($userfile, "r" );
$image->save(fread($fp, filesize($userfile ) ) );
fclose($fp );
ocicommit($conn );

ocifreestatement($stmt );

} else {
?>
    <form method="post" action=" <?php echo $php_self; ?>" enctype="multipart/form-data">
    file description:<br>
    <input type="text" name="description"  size="40">
    <input type="hidden" name="max_file_size" value="1000000">
    <br>file to upload/store in database:<br>
    <input type="file" name="userfile"  size="40">
    <p><input type="submit" name="submit" value="submit">
    </form>

<?php
}
?>
</body>
</html>
//display.php
<?php
/*
  purpose:
    display an image from picture table
*/
dl("php_oci8.dll");
$conn = ocilogon("scott","tiger");
$stmt = ociparse($conn, "select image, imgtype from picture where picid=23" );
ociexecute($stmt);

@ocifetchinto($stmt, &$result, oci_assoc);
header("content-type: image/".$result[imgtype]);
echo $result[image]->load();

ocilogoff($conn );
?>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Oracle中图片的存贮与显示例程-PHP教程,PHP应用
分享到: 更多 (0)