upload file to Oralce Blob

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jiehuang001
Forum Commoner
Posts: 39
Joined: Mon May 12, 2003 12:53 pm

upload file to Oralce Blob

Post 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);
Post Reply