Oracle中图片的存贮与显示例程
时间:2007-02-17 来源:PHP爱好者
作者/来源:star2002
Oracle中图片的存贮与显示例程
//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>
";
echo "File size: <b>$userfile_size</b>
";
$hwsize = GetImageSize($userfile );
$w = $hwsize[0];
$h = $hwsize[1];
echo "Image width: <b>$w</b>
";
echo "Image b>$h</b>
";
$ImgType = strtolower(substr( strrchr( $userfile_name, "." ), 1 ) );
if ($ImgType == "jpg")
$ImgType = "jpeg";
echo "Image type: <b>$ImgType</b>
";
echo "Created date; <b>".date(’Y-m-d’)."</b>
";
$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:
<input type="text" name="description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
File to upload/store in database:
<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 );
?>
php爱好者站 http://www.phpfans.net dreamweaver|flash|fireworks|photoshop.
Oracle中图片的存贮与显示例程
//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>
";
echo "File size: <b>$userfile_size</b>
";
$hwsize = GetImageSize($userfile );
$w = $hwsize[0];
$h = $hwsize[1];
echo "Image width: <b>$w</b>
";
echo "Image b>$h</b>
";
$ImgType = strtolower(substr( strrchr( $userfile_name, "." ), 1 ) );
if ($ImgType == "jpg")
$ImgType = "jpeg";
echo "Image type: <b>$ImgType</b>
";
echo "Created date; <b>".date(’Y-m-d’)."</b>
";
$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:
<input type="text" name="description" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000">
File to upload/store in database:
<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 );
?>
php爱好者站 http://www.phpfans.net dreamweaver|flash|fireworks|photoshop.
相关阅读 更多 +