store and retrieve a (jpg) picture into a blob field ?

Posted on 2006-01-11 10:33 风清云淡 阅读(144) 评论(0)  编辑  收藏 所属分类: PHP
 Jun 13th, 2003 15:18
Peter Theill, Andi Worx, Patrick Mahla,


$dbcon = OCILogon($dbUser,$dbPassword,$dbName);
$lob = OCINewDescriptor($dbcon, OCI_D_LOB);
$data = fread(fopen($form_data, "r"), filesize($form_data));
$query = "insert into IMAGE_DATA (";
$query .= "NUM_IMAGEID, STR_IMAGE_TYPE, BLO_IMAGE_DATA";
$query .= ") values (";
$query .= "NUM_ID.NEXTVAL, $form_data_type, EMPTY_BLOB()";
$query .= ") returning BLO_IMAGE_DATA into :img_blob";
$stmt = OCIParse($dbcon,$query);
OCIBindByName($stmt, ':img_blob', &$lob, -1, OCI_B_BLOB);
if (OCIExecute($stmt,OCI_DEFAULT)) {
if($lob->save($data)){
OCICommit($dbcon);
OCIFreeStatement($stmt);
echo "Blob successfully uploaded\n";
}else{
OCIFreeStatement($stmt);
echo "Couldn't upload Blob\n";
}
}
OCILogoff($dbcon);

--------------------------------------------------------------

If you use this Codesnippet, you can store BLOB to an oracledb!
The next Codesnippet you can view the images!

-------------------------------------------------------------

$dbcon = OCILogon($dbUser,$dbPassword,$dbName);
$query = "select * from IMAGE_DATA where NUM_ID=$id";
$stmt = OCIParse($dbcon, $query);
OCIExecute($stmt, OCI_DEFAULT);
while (OCIFetchInto($stmt, $row, OCI_ASSOC)) {
$data = $row["BLO_IMAGE_DATA"]->load();
}
$type = OCIResult($stmt,"STR_IMAGE_TYPE");
OCIFreeStatement($stmt);

Header( "Content-type: $type");
echo $data;

cu
AndiWorx

 


只有注册用户登录后才能发表评论。


网站导航:
 

posts - 1, comments - 0, trackbacks - 0, articles - 3

Copyright © 风清云淡