After a search I found a few results, but none were in PHP environment.
what I'm trying to do is have a user upload a pdf file into an oracle database. (as a clob data type) I can upload no problem, but it comes time to retrive the info into a pdf file I get 2 outcomes depending on how I tamper with the php code.
1) the pdf file opens, but it's empty.
2) I get a format error and the pdf file does not open
When I check if the info is actually in oracle, everything seems to be ok at the database level. I figure I'm doing something wrong in php when I insert the data or when i'm trying to retrieve the data. I am using oracle 10g.
Any help would be greatly appreciated...
In case I lost some of you with my explanation, I am inserting a pdf file into oracle and want to retrive it in the pdf reader. Thats all...
here is the code I'm using...
Code:
//
// Sample form to upload and insert data into an ORACLE CLOB column
// using PHP's Oracle 8 API.
//
// Based on http://www.php.net/manual/en/functio...descriptor.php
// modified to work on CLOBs and use register_globals = Off.
//
// Before running this script, execute these statements in SQL*Plus:
// drop table myclobtab;
// create table myclobtab (c1 number, c2 clob);
//
// Tested with PHP 4.3.3 against Oracle 9.2
//
if (!isset($_FILES['lob_upload'])) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
Upload file: <input type="file" name="lob_upload">
<input type="submit" value="Upload">
</form>
<?php
}
else {
$myid = 1; // should really be a unique id e.g. a sequence number
$conn = OCILogon('myusername', 'mypassword', 'mydatabase');
// Delete any existing CLOB so the query at the bottom
// displays the new data
$query = 'DELETE FROM MYCLOBTAB';
$stmt = OCIParse ($conn, $query);
OCIExecute($stmt, OCI_COMMIT_ON_SUCCESS);
OCIFreeStatement($stmt);
// Insert the CLOB from PHP's temporary upload area
$lob = OCINewDescriptor($conn, OCI_D_LOB);
$stmt = OCIParse($conn, 'INSERT INTO MYCLOBTAB (C1, C2) VALUES('.$myid . ', EMPTY_CLOB()) RETURNING C2 INTO :C2');
OCIBindByName($stmt, ':C2', &$lob, -1, OCI_B_CLOB);
OCIExecute($stmt, OCI_DEFAULT);
// The function $lob->savefile(...) reads from the uploaded file.
// If the data was already in a PHP variable $myv, the
// $lob->save($myv) function could be used instead.
if ($lob->savefile($_FILES['lob_upload']['tmp_name'])) {
OCICommit($conn);
echo "CLOB successfully uploaded\n";
}
else {
echo "Could not upload CLOB\n";
}
$lob->free();
OCIFreeStatement($stmt);
// Now query the uploaded CLOB and display it
$query = 'SELECT C2 FROM MYCLOBTAB WHERE C1 = '.$myid;
$stmt = OCIParse ($conn, $query);
OCIExecute($stmt, OCI_DEFAULT);
OCIFetchInto($stmt, $arr, OCI_ASSOC);
$result = $arr['C2']->load();
header("Pragma: no-cache");
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
echo $result;
OCIFreeStatement($stmt);
OCILogoff($conn);
}