petrakid 0 Newbie Poster

Normally when I do file uploads I save the files into the website's file system. However in this particular situation I am required to save the PDF files as a longblob into a table in our mysql database.

The data field is set as a longblob, and the table is setup as an innoDB.

I also save the file size the file name and the file type. The file upload works just fine.

I have also checked the blob data and the data begins with "%PDF-" as required. However whenever I try to download the file OR embed it, I get the error "File does not begin with '%PDF-'". I've done some looking around and I am not finding any answers (though several similar issues).

Here is the code for retrieving and displaying/downloading the file (with the assumption that I've already done the database query)

ob_start();
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Expires: 0");
header('Content-length: '. $val['upload_filesize']);
header("Content-type: ". $val['upload_filetype'] ."");
header('Content-Disposition: inline; filename="'. $val['upload_filename'] .'"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes'); 
          
echo $val['upload_filecontent'];
exit;

Now I have tried to use the Google Docs inline viewer (inline), tried to simply download the file (attachment) (the file downloads but it's corrupt), and tried a standard embed which would call Adobe Reader.

Any suggestions (other than 'store on filesystem instead') are appreciated. I CANNOT store on the filesystem due to file count restrictions.