当前位置导航:炫浪网>>网络学院>>编程开发>>Oracle教程

Oracle中图片的存贮与显示例程




// 如果提交了表单,代码将被执行:
dl("php_oci8.dll");
$conn = OCILogon("scott","tiger");
if ($submit) {
echo "File name: $userfile_name
";
echo "File size: $userfile_size
";
$hwsize = GetImageSize($userfile );
$w = $hwsize[0];
$h = $hwsize[1];
echo "Image width: $w
";
echo "Image height: $h
";
$ImgType = strtolower(substr( strrchr( $userfile_name, "." ), 1 ) );
if ($ImgType == "jpg")
  $ImgType = "jpeg";
echo "Image type: $ImgType
";
echo "Created date; ".date("Y-m-d")."
";
$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 "

$sql
";
$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 {
?>
   

    File Description:

   
   
   
File to upload/store in database:

   
   


   

 

}
?>


//display.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 );
?> 

相关内容
赞助商链接