快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

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><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 );
?>





返回类别: 教程
上一教程: 用php实现gb2312和unicode间的编码转变
下一教程: PHP:路在何方?

您可以阅读与"Oracle中图片的存贮与显示例程"相关的教程:
· 用php+oracle实现分页的示例程序
· 我写的一个用PHP+MYSQL轻松实现论坛里的分级+分页显示的例程!(很具体的哦!虽然效率不是最佳,却非...
· 用PHP调用数据库的存贮过程
· 在PHP3中实现SESSION的功能(三、示例程序:test_session.php3)
· 用PHP调用数据库的存贮过程!
    微笑服务 优质保证 索取样品