• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-7-01 15:06 | 作者: admin | 来源: | 查看: 17次 | 进入软件测试论坛讨论

领测软件测试网 //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 );
?>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网