此代码应将blob文件映像上传到oracle数据库。当我尝试使用以下代码时,变量$objExecute
会产生错误!
请帮助解决此问题。
$error= $_FILES['Image_assigned']['error'];
$objConnect = oci_connect("jab","jabee","j-windows7/XE");
$lob = oci_new_descriptor($objConnect, OCI_D_LOB);
$strSQL ="insert into SS_USERS_PIC (SYSUID,PICTURE) values (F_SS_GET_AUTO_ID('SYSUID','PICTURE') , EMPTY_BLOB()) RETURNING ImageFile INTO :BLOBDATA " .")";
// $strSQL='insert into mybtab (blobid, blobdata) values (:myblobid, EMPTY_BLOB()) returning blobdata into :blobdata';
$objParse = oci_parse($objConnect, $strSQL);
oci_bind_by_name($objParse, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
$objExecute = oci_execute($objParse, OCI_DEFAULT);
$lob->savefile($_FILES['Image_assigned']['tmp_name']);
$errorCode= $_FILES['Image_assigned']['error'];
if ($objExecute)
{
oci_commit($objConnect);
echo "Copy/Upload Complete<br>";
}
else
{
oci_rollback($objConnect);
trigger_error(htmlentities($e['message']), E_USER_ERROR);
echo "Copy/Upload is not Complete";
}
答案 0 :(得分:0)
function upload($operation){
if(!empty($_FILES['Image_assigned']['name']) && !($_FILES['Image_assigned']['error']))
{
$uploadedFile = '';
if(!empty($_FILES["Image_assigned"]["type"]))
{
$fileName = time().'_'.$_FILES['Image_assigned']['name'];
$valid_extensions = array("jpeg", "jpg", "png");
$temporary = explode(".", $_FILES["Image_assigned"]["name"]);
$file_extension = end($temporary);
$blobdata = file_get_contents($_FILES['Image_assigned']['tmp_name']);
if((($_FILES["hard_file"]["type"] == "image/png") || ($_FILES["Image_assigned"]["type"] == "image/jpg") || ($_FILES["Image_assigned"]["type"] == "image/jpeg")) && in_array($file_extension, $valid_extensions))
{
$sourcePath = $_FILES['Image_assigned']['tmp_name'];
$targetPath = "uploads/".$fileName;
}
}
$objConnect = oci_connect("[username]","[password]","[hostname]/[instnce_name]");
$lob = oci_new_descriptor($objConnect, OCI_D_LOB);
if ($operation=='ADD'){
$strSQL ="insert into [TableName] (PICTURE) values ( EMPTY_BLOB()) RETURNING PICTURE INTO :BLOBDATA ";
$objParse = oci_parse($objConnect, $strSQL);
}
// *************************************
oci_bind_by_name($objParse, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
try
{
$objExecute = oci_execute($objParse, OCI_DEFAULT);
$lob->savefile($_FILES['Image_assigned']['tmp_name']);
}
catch (Exception $e) {
$err = $e->getMessage();
}
if($objExecute)
{
oci_commit($objConnect);
echo "Copy/Upload Complete<br>";
}
else
{
oci_rollback($objConnect);
trigger_error(htmlentities($e['message']), E_USER_ERROR);
echo "Copy/Upload is not Complete";
}
oci_free_descriptor($lob);
oci_free_statement($objParse);
oci_close($objConnect);
}
}