Page 1 of 1

upload file to Oralce Blob

Posted: Thu May 22, 2003 2:06 pm
by jiehuang001
Can someone be kind enough to show me a WORKING code on how to upload a file into an Oracle blob field? It has been pain for me to do that in JSP. I hope it is easier for PHP. I have seen some example code like the following, but unfortunately it doesn't work. Please help.

$filename = $_POST['fileupload'];
$fd = fopen( $filename, "r" );
$contents = fread( $fd, filesize( $filename ) );
fclose( $fd );

$clob = OCINewDescriptor($conn, OCI_D_LOB);
$query = "INSERT INTO clobtest (clob_id, clobcol) VALUES ".
"(clob_id_seq.nextval, EMPTY_CLOB()) ".
"RETURNING clobcol INTO :the_clob";
$stmt = OCIParse($conn, $query);
OCIBindByName($stmt, ":the_clob", &$clob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);
$clob->save($contents);
OCICommit($conn);