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