[DUPLICATE]File uploads, but BLOB has 0 length
Posted: Thu Jul 14, 2011 2:50 pm
TURNS OUT THIS IS A RED HERRING, THE SOLUTION TO THE THREAD BELOW WAS NOT A SOLUTION. ACTUAL ISSUE LINKED BELOW IS STILL AN UNRESOLVED ISSUE.
viewtopic.php?f=1&t=130457
Okay, I'm still trying to troubleshoot this piece of code. Some of you may have seen it before, as I'm working through the issues that I'm having with it.
The current issue is that I go through the code, getting good results from every operation, and when I go to check the size of the file in the BLOB column in Oracle, it's got a size of zero (0).
This is what I find from SQL+

viewtopic.php?f=1&t=130457
Okay, I'm still trying to troubleshoot this piece of code. Some of you may have seen it before, as I'm working through the issues that I'm having with it.
The current issue is that I go through the code, getting good results from every operation, and when I go to check the size of the file in the BLOB column in Oracle, it's got a size of zero (0).
Code: Select all
public function loadBLOBFile($filePurpose, $fileType, $fileName, $fileSize){
if(!isset($_SESSION['user'])) $_SESSION['user']=1;
$sequence = "blobs_seq";
$myblobid = $this->getNextId($sequence);
$conn = $this->getConnection();
// Delete any existing BLOB
$query = 'DELETE FROM blobTbl WHERE FILEPURPOSE = :FILEPURPOSE '.
'AND USERID = :USERID';
$stid = oci_parse ($conn, $query);
if(!$stid){
$err = oci_error($stid);
$this->setOciErrorMsg($err);
return;
}
oci_bind_by_name($stid, ':FILEPURPOSE', $filePurpose);
oci_bind_by_name($stid, ':USERID', $_SESSION['user']);
$e = oci_execute($stid, OCI_COMMIT_ON_SUCCESS);
if(!$e){
$err = oci_error($e);
$this->setOciErrorMsg($err);
return;
}
oci_free_statement($stid);
// Insert the BLOB from PHP's temporary upload area
$lob = oci_new_descriptor($conn, OCI_DTYPE_LOB);
$stid = oci_parse($conn, 'INSERT INTO blobTbl (BLOBID, FILETYPE, '.
'USERID, FILEPURPOSE, FILENAME, FILESIZE, FILEDATA) VALUES '.
'(:MYBLOBID, :FILETYPE, :USERID, :FILEPURPOSE, :FILENAME, '.
':FILESIZE, EMPTY_BLOB()) RETURNING FILEDATA INTO :BLOBDATA');
if(!$stid){
$err = oci_error($stid);
$this->setOciErrorMsg($err);
return;
}
oci_bind_by_name($stid, ':MYBLOBID', $myblobid);
oci_bind_by_name($stid, ':FILEPURPOSE', $filePurpose);
oci_bind_by_name($stid, ':FILETYPE', $fileType);
oci_bind_by_name($stid, ':USERID', $_SESSION['user']);
oci_bind_by_name($stid, ':FILENAME', $fileName);
oci_bind_by_name($stid, ':FILESIZE', $fileSize);
oci_bind_by_name($stid, ':BLOBDATA', $lob, -1, OCI_B_BLOB);
$success = oci_execute($stid, OCI_DEFAULT);
if(!$success){
$err = oci_error($stid);
$this->setOciErrorMsg($err);
}
// The function $lob->import(...) reads from the uploaded file.
if ($lob->save($_FILES['lob_upload']['tmp_name'])) {
oci_commit($conn);
$msg = "File upload was successful.\n";
}else{
$msg = "Couldn't upload file.\n";
}
$lob->free();
oci_free_statement($stid);
return $msg;
}
The first is a text file I uploaded during testing, the second is a PDF I tried uploading once I got the code converted into my app class.SQL> select dbms_lob.getlength(filedata)
2 from blob_tbl;
DBMS_LOB.GETLENGTH(FILEDATA)
----------------------------
672
0