I just recently asked and solved a question pertaining to uploading .PDF files that are greater than 2 MB into a MySQL database as BLOBS. I had to change some settings in my php.ini file and MySQLs maximum packet setting. However, fixing this issue has led me to discover a new issue with my script.
Now since I can upload files to my BLOB database I attempted to download the file for testing purposes. Much to my dismay when I went to open the .PDF file I received the following error: Failed to load document (error 3) 'file:///tmp/test-13.pdf'. Upon further investigation I found out that the file being downloaded, test.pdf, was only 1 MB, a little less than half of its supposed size in the database of a little more than 2 MB. This is obviously the reason for the error.
The following piece of code is the part of my script I am using for downloading files from the database. It is is at the very top of of script and works Flawlessly for files that are less than 1 MB.
foreach($_REQUEST as $key => $value)
{
if ($value == 'Open')
{
header();
session_start();
$dbh = new PDO('mysql:host='.$_SESSION['OpsDBServer'].'.ops.tns.its.psu.edu;
dbname='.$_SESSION['OpsDB'], $_SESSION['yoM'], $_SESSION['aMa']);
$id = $key;
$sqlDownload = "SELECT name, type, content, size FROM upload WHERE
id='".$id."'";
$result = $dbh->query($sqlDownload);
$download = $result->fetchAll();
$type = $download[0]['type'];
$size = $download[0]['size'];
$name = $download[0]['name'];
$content = $download[0]['content'];
header("Content-type: $type");
header("Content-Disposition: inline; filename=$name");
header("Content-length: $size");
header("Cache-Control: maxage=1");
header("Pragma: public");
echo $content;
exit;
}
}
I am thinking that maybe I have some header statements wrong? I am very confused about what to do. I have searched through php.ini and I have found no settings that I think need to changed and my maximum packet setting for MySQL is 4 MB so a 2 MB should download.
Thanks for any help.