您的位置:首页 > 数据库 > Oracle

php 存储文件到oracle blob 字段

2009-05-22 14:35 471 查看
<?php
/* This script demonstrates file upload to LOB columns
* The formfield used for this example looks like this
* <form action="upload.php" method="post" enctype="multipart/form-data">
* <input type="file" name="lob_upload" />
* ...
*/
$lob_upload = $_FILES['lob_upload'];
if (!isset($lob_upload) || $lob_upload == 'none'){
?>
<form method="post" enctype="multipart/form-data">
Upload file: <input type="file" name="lob_upload" /><br />
<input type="submit" value="Upload" /> - <input type="reset" value="Reset" />
</form>
<?php
} else {

// $lob_upload contains the temporary filename of the uploaded file
// see also the features section on file upload,
// if you would like to use secure uploads
ini_set('display_errors',1);
$db_host   = "//192.168.1.9/JSHDB";
$db_user   = "lterp";
$db_pass   = "juyitong2009";
$conn = oci_connect($db_user, $db_pass,$db_host);
$lob = oci_new_descriptor($conn, OCI_D_LOB);
$table = 'PICTURES';
$stmt = oci_parse($conn, "insert into $table (id, the_blob)
values(my_seq.NEXTVAL, EMPTY_BLOB()) returning the_blob into :the_blob");

oci_bind_by_name($stmt, ':the_blob', $lob, -1, OCI_B_BLOB);
oci_execute($stmt, OCI_DEFAULT);
if ($lob->saveFile($lob_upload['tmp_name'])){
oci_commit($conn);
echo "Blob successfully uploaded/n";
}else{
echo "Couldn't upload Blob/n";
}
oci_free_descriptor($lob);
oci_free_statement($stmt);
oci_close($conn);
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: