title: Large .PDF Files Not Uploading To MySQL Database as Medium BLOB Via PHP, Files under 2MB Work Fine
body: <p>I am developing a PHP script for uploading .PDF documents as medium BLOBs into a MySQL database via PHP.  The script also allows users to search for files and open/download them but I do not think that part of the script is relevant to my issue.  The script works fine with files less than 2 MB but as soon as I try and upload a file that is more than 2 MB nothing is going into my content(Medium BLOB) column and there is no value for the mime type.  I have already tried increasing the max_packet_size for the MySQL server to 4 MB from its default value of 1 MB.  I have also updated php.ini to the correct values, I think.  I set upload_max_size to 4MB, post_max_size to 4 MB, and memory_limit to 16 MB.  I haven't really experimented with the max_input_time though because it is defaulted to 60 seconds which seems like plenty considering this script is for an internal application on an intranet.  </p>
  
  <p>I have also tried to catch errors from the PDO object in my script with errorInfo() and errorCode() and both through 0s (no error).  </p>
  
  <p>Here is the upload section of my script:</p>
  
  <pre><code>if ($key == 'upload')
  {
      set_time_limit(0);
      $_SESSION['upload'] = $value;
  
      if ($_FILES['userfile']['name'])
      {
          $fileName = $_FILES['userfile']['name'];
          $tmpName  = $_FILES['userfile']['tmp_name'];
          $fileSize = $_FILES['userfile']['size'];
          $fileType = $_FILES['userfile']['type'];
          $docType = $_POST['docType'];
          $netKey = $_POST['netKey'];
          $fp       = fopen($tmpName, 'r');
          $content  = fread($fp, filesize($tmpName));
          $content  = addslashes($content);
          fclose($fp);
  
          $_SESSION['filetype'] = $fileType;
  
          if(!get_magic_quotes_gpc())
          {
              $fileName = addslashes($fileName);
          }
          $sqlCheck = "SELECT id, name, documentType, networkKey FROM upload WHERE active='1'";
          foreach ($dbh-&gt;query($sqlCheck) as $row)
          {
              if (($row['name'] == $fileName) &amp;&amp; ($row[networkKey] == $netKey) &amp;&amp; ($row['documentType'] == $docType)) 
              {
                  $_SESSION['updateRow'] = $row['id'];
              }
  
          }
  
          if ($_SESSION['updateRow'])
              {
                  $deactivateDuplicate = "UPDATE upload SET active = 0, modifiedBy = '".strtoupper($_SERVER['REMOTE_USER'])."', modifiedDate = Now() WHERE id = '".$_SESSION['updateRow']."' AND active ='1'";
                  $dbh-&gt;query($deactivateDuplicate);
                  $_SESSION['sql'] = "SELECT id, name, documentType, type, size, networkKey, modifiedBy, modifiedDate, active FROM upload WHERE active = '1'";
                  $_SESSION['uploadSearch'] = 1;
                  $_SESSION['updateRow'] = 0;
              }
              $values = "'".$fileName."','".$docType."','".$fileType."','".$content."','".$fileSize."','".$netKey."','".strtoupper($_SERVER['REMOTE_USER'])."', Now(), 1";
              $sqlUpload = "INSERT INTO upload (name, documentType, type, content, size, networkKey, modifiedBy, modifiedDate, active) VALUES (".$values.")";
              $dbh-&gt;query($sqlUpload);
  
              $_SESSION['sql'] = "SELECT id, name, documentType, type, size, networkKey, modifiedBy, modifiedDate, active FROM upload WHERE active = '1'";
              $_SESSION['uploadSearch'] = 1;
  
  
      }
  }
  </code></pre>
  
  <p>And Here is the front end of the application showing that a smaller file works and a larger file does not.  The file sample.pdf is less than 1 MB and the file test.pdf is 2.5 MB.  </p>
  
  <p><a href="http://www.imagechicken.com/viewpic.php?p=1255628359017775300&amp;x=png" rel="noreferrer">http://www.imagechicken.com/viewpic.php?p=1255628359017775300&amp;x=png</a></p>
  
  <p>I would have used img tags but alas I am a new user and not allowed.</p>
  
  <p>The next thing I am going to look for is a setting in Apache that limits file sizes.  I am new to LAMP so any tips would be great.
  Thanks</p>