title: mysql blob image not displaying
body: <p>I'm having a problem getting my images to display after extracting them from a database.
  I have 2 separate tables, one for the meta data and another to hold the actual blob data. that table is a regular BLOB and i only store 60k chunks of data in each row. I recompile the image when i want to render it. </p>
  
  <p>i keep getting this error though:</p>
  
  <p>the image "http://imgStore.localhost/ImageBuilder/index/id/11" cannot be displayed because it contains errors.</p>
  
  <p>here is how the flow works however.</p>
  
  <p>/Images/image/id/11 will have an image inside of it like this</p>
  
  <pre><code>&lt;img src="http://imgStore.localhost/ImageBuilder/index/id/11" /&gt;
  </code></pre>
  
  <p>the Images controller handles insertions and edits as well as listing the images
  while ImageBuilder is only concerned with displaying a given image</p>
  
  <p>here is the table structure:</p>
  
  <pre><code>images ------
  image_id    INT
  image_name  VARCHAR
  image_type  VARCHAR
  image_size  INT
  loaded_date DATETIME
  
  image_data --
  image_data_id  INT
  image_id       INT
  data           BLOB
  </code></pre>
  
  <p>here is how i save the file into the database:</p>
  
  <p>( NOTE: i'm using the latest Zend Framework )</p>
  
  <p>( insertion action ) ------------------</p>
  
  <pre><code>$image  = new ImgStore_Model_Images($form-&gt;getValues());
  $image-&gt;setImage_size(((int) substr($form-&gt;image_file-&gt;getFileSize(), 0, -2) * 1024));
  $image-&gt;setImage_type($form-&gt;image_file-&gt;getMimeType());
  $image-&gt;setLoaded_date(time());
  $image-&gt;setLoaded_by($user-&gt;get('contacts_id'));
  $mapper = new ImgStore_Model_ImagesMapper();
  $image_id = $mapper-&gt;save($image);
  
  // open the uploaded file to read binary data
  $fp = fopen($form-&gt;image_file-&gt;getFileName(), "r");
  $dataMapper = new ImgStore_Model_ImageDataMapper();
  // loop through the file and push the contents into
  // image data entries
  
  while( !feof($fp) ){
   // Make the data mysql insert safe
   $binary_data = addslashes(fread($fp, 60000));
  
   $data_entry = new ImgStore_Model_ImageData();
   $data_entry-&gt;setImage_id($image_id);
   $data_entry-&gt;setImage_data($binary_data);
  
       $dataMapper-&gt;save($data_entry);
  }
  fclose($fp);
  </code></pre>
  
  <p>and here is how it is extracted:</p>
  
  <p>(action) ------------------</p>
  
  <pre><code>$this-&gt;_helper-&gt;_layout-&gt;disableLayout();
  
  // get the image meta data
  $image_id   = $this-&gt;_request-&gt;getParam('id', '0');
  
  $mapper = new ImgStore_Model_ImagesMapper();
  $info   = $mapper-&gt;getInfo($image_id);
  
  // build the image and push it to the view
  $mapper            = new ImgStore_Model_ImageDataMapper();
  $this-&gt;view-&gt;image = $mapper-&gt;buildImage($image_id);
  $this-&gt;view-&gt;name  = $info-&gt;getImage_name();
  $this-&gt;view-&gt;type  = $info-&gt;getImage_type();
  $this-&gt;view-&gt;size  = $info-&gt;getImage_size();
  </code></pre>
  
  <p>(model) ------------------</p>
  
  <pre><code>public function buildImage($image_id)
  {
       // get the image data
       $sql = "SELECT image_data
               FROM image_data
               WHERE image_id='$image_id'
               ORDER BY image_data_id ASC";
       $results = $this-&gt;_adapter-&gt;fetchAll($sql);
  
       // piece together the image and return it
       $image = NULL;
       foreach( $results as $row ){
            $image .= $row['image_data'];
       }
       return $image;
  } #end buildImage function
  </code></pre>
  
  <p>(view) ------------------</p>
  
  <pre><code>&lt;?php
  
  header( "Content-Type: " . $this-&gt;type );
  header('Content-Disposition: inline; filename="'.$this-&gt;name.'"');
  
  echo $this-&gt;image;
  
  ?&gt;
  </code></pre>
  
  <p>i have tried to use an image that was small enough to take up only one row in the image_data table as well, so i don't believe it has anything to do with the recompilation of the image_data rows.</p>
  
  <p>any help would be appreciated, i truly have no idea what is wrong with this.</p>
  
  <hr>
  
  <p>edited some formatting for display purposes.</p>