Please test my website at http://198.108.102.145/vbfiles (use "testit" as both username and password). As you will see, you can upload and downlaod text files without problem. However, if you upload a binary file such as a .doc file, you will get problem to open it after downloading. Below is my code for uploading and downloading, please tell me how to modify this code to make it work for binary files.
Also, in my downloading code, i passed the $file_name variable from previous page. How can I get it from the query directly, with only $id is passed?
Thanks.
Jie Huang
---------------upload file to Oracle database--------------
for ($i=0; $i<$add_number; $i++){
$TmpName = $FILES['userfile']['tmp_name'][$i];
$FileName = $FILES['userfile']['name'][$i];
$FileType = $_FILES['userfile']['type'][$i];
if($FileName!=""){
$FilePointer = fopen($TmpName,"r");
$FileContents = fread($FilePointer, filesize($TmpName) );
fclose($FilePointer);
$query = "INSERT INTO lexicon_files VALUES (file_sequence.nextval, '$FileName', '$FileType', EMPTY_BLOB(), 'No', sysdate, '$username') RETURNING file_content INTO :the_blob";
$stmt = OCIParse($conn, $query);
$blob = OCINewDescriptor($conn, OCI_D_LO😎;
OCIBindByName($stmt, ":the_blob", &$blob, -1, OCI_B_BLO😎;
OCIExecute($stmt, OCI_DEFAULT);
$blob->save($FileContents);
OCICommit($conn);
//OCIFreeDescriptor($blob);
OCIFreeStatement($stmt);
OCILogoff($conn);
}
}
----------------download file from Oracle database-----------------
<?php
include_once("Connection.txt");
$id = $REQUEST['id'];
$file_name = $REQUEST['file_name'];
$stmt = OCIParse($conn, "select file_content from lexicon_files where id=".$id);
OCIExecute($stmt);
OCIFetchInto($stmt, &$blob);
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename="'.$file_name.'"');
print $blob[0]->load();
OCIFreeStatement($stmt);
OCILogoff($conn);
?>