BLOB upload Truncated by 1 MB Script Works with files less than 1 MB

I recently asked and resolved a question related to uploading .PDF files larger than 2MB to MySQL database as BLOBS. I had to change some parameters in php.ini file and max set of MySQL packages. However, fixing this issue led me to discover a new problem with my script.

Now that I can upload files to my BLOB database, I have tried uploading a file for testing. Much to my disappointment, when I went to open the .PDF file, I got the following error: Failed to load document (error 3) 'file: ///tmp/test-13.pdf'. Upon further investigation, it turned out that the download file test.pdf was only 1MB, which is just under half of its estimated size in the database at just over 2MB. This is obviously the reason for the error.

The following piece of code is part of my script that I am using to download files from the database. It sits at the very top of the script and works flawlessly for files less than 1MB in size.

 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 think maybe I have some header assertions wrong? I am very confused about what to do. I have searched through php.ini and I didn't find any options that I think need to be changed and my max package setting for MySQL is 4 MB, so 2 MB needs to be downloaded.

Thanks for any help.

+2


source to share


2 answers


I actually fixed the problem. I changed all the values ​​that were recommended here in php.ini and my.cnf, but I also needed to change the parameter for PDO.

I changed: PDO :: MYSQL_ATTR_MAX_BUFFER_SIZE (integer) Maximum buffer size. The default is 1 MiB.



This must be set when the PDO is created to work. All is well now.

+2


source


According to ( http://dev.mysql.com/doc/refman/5.0/en/blob.html ):

The maximum size of a BLOB or TEXT is determined by its type, but the largest value you can actually transfer between the client and server is determined by the amount of available memory and the size of the communication buffers. You can change the size of the message buffer by changing the value of max_allowed_packet, but you must do this for the server and your client program.



According to ( http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html ) the default value for max_allowed_packet is 1048576.

+2


source







All Articles