I am working on a bbs program which uses oracle BLOBs to store attachments that users may upload. and the program is designed to display images directly when data is fetched. and other types of files such as .rar,.zip etc. will be downloaded at client side. however, a weird problem occured.
the program is listed below:

$conn=ocilogon($user, $password, $tnsname);
$sql=SELECT filename,filedata,filetype FROM attachment WHERE attachmentid=$id";
$stmt=ociparse($conn,$sql);
ociexecute($stmt);
OCIFetchInto($stmt, &$attachmentinfo);
header("Content-disposition:$attachment filename=$attachmentinfo[0]");
header("Content-Length: ".strlen($attachmentinfo[1]));

if ($attachmentinfo[2]=='gif') {
  header('Content-type: image/gif');
} elseif ($attachmentinfo[2]=='jpg' or $attachmentinfo[2]=='jpeg') {
  header('Content-type: image/jpeg');
} elseif ($attachmentinfo[2]=='png') {
  header('Content-type: image/png');
} else {
  header('Content-type: application/octet-stream');
}
echo $attachmentinfo[1]->load();

the problem is: all images files that are retrieved from database can be displayed well. but other types of files like rar can only be partly downloaded. for example, a 600k bytes size file will only have 4K bytes after it is download. and I use sqlplus to check
SQL>select dbms_lob.getlength(filedata) from attachment£»
it seems the file in database has the same size with its original one. so I guess there must be something wrong with the code above. however, I cannot find the problem after searching web.
I am so confused, please give me a hand. thanks a lot!!

    2 years later

    Can you tell me how you inserted your files into Oracle?

    thanks...

      Write a Reply...