title: Trouble Inserting a Image Data to LongBlob Field
body: <p>Total newbie here, please bear with me.</p>
  
  <p>Building a very small personal app that uploads some images and info. I can't figure out why the following PHP/MySQL doesn't add the last insert in the query (<code>$file_data</code>) to my DB's longblob field. </p>
  
  <p>All the other fields in the query insert fine, meaning I tested them one at a time, adding to the query, until I got to the last and then the insert fails. I am able to echo <code>$file_data</code> before the insert and see that the data is there, I've also found that hardcoding a string value for <code>$file_data</code> (i.e <code>$file_data="this will insert"</code>) inserts fine... which is frustrating. </p>
  
  <p>So my guesses are there's an error in the reading of the file (<code>$fp fread</code> etc) or that my longblob is setup wrong. File sizes are &lt;16kb, so I'm sure it's not a php.ini issue either.</p>
  
  <p>Any ideas? Thanks.</p>
  
  <pre><code>$boxtype=$_POST['type'];
  $title=$_POST['title'];
  
  if(isset($_POST['submit']) &amp;&amp; $_FILES['imgfile']['size'] &gt; 0)
  {
  
      $filename = $_FILES['imgfile']['name'];
      $tmpName = $_FILES['imgfile']['tmp_name'];
      $file_size = $_FILES['imgfile']['size'];
      $mime_type = $_FILES['imgfile']['type'];        
  
      $fp = fopen($tmpName, 'r');
      $file_data = fread($fp, filesize($tmpName));
      fclose($fp);
  
      $query = "INSERT INTO table 
           (boxtype,title,filename,mime_type,file_size,file_data) 
           VALUES 
           ('$boxtype','$title','$filename','$mime_type','$file_size','$file_data')
           ";
  
      $db = db_connect(); 
      $result = $db-&gt;query($query) or die('Error, query failed');
  
      if ($result) 
      {
         echo "&lt;br&gt;Success&lt;br&gt;";
      }
  }
  else die("No Content");
  </code></pre>
  
  <p>MySQL Table:</p>
  
  <pre><code>CREATE TABLE `port` (
    `id` int(2) unsigned zerofill NOT NULL AUTO_INCREMENT,
    `boxtype` tinytext COLLATE latin1_general_ci NOT NULL,
    `title` varchar(40) CHARACTER SET latin1 NOT NULL,
    `filename` varchar(255) COLLATE latin1_general_ci NOT NULL,
    `mime_type` varchar(255) COLLATE latin1_general_ci NOT NULL,
    `file_size` int(11) NOT NULL,
    `file_data` longblob NOT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
  </code></pre>