title: display image - blob - not correct
body: <p>somewhere I'm going terribly wrong.  I'm trying to display an image from a MySQL table in php.  I'll start from the beginning.</p>
  
  <p><strong>uploadform</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
      &lt;head&gt;
        &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form action="add_file.php" method="post" enctype="multipart/form-data"&gt;
              &lt;input type="file" name="uploaded_file"&gt;&lt;br /&gt;
              &lt;input type="submit" value="Upload file"&gt;
          &lt;/form&gt;
          &lt;p&gt;
              &lt;a href="list_files.php"&gt;See all files&lt;/a&gt;
          &lt;/p&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong>add_file.php</strong></p>
  
  <pre><code>&lt;?php
  // Check if a file has been uploaded
  if(isset($_FILES['uploaded_file'])) {
      // Make sure the file was sent without errors
      if($_FILES['uploaded_file']['error'] == 0) {
          // Connect to the database
          $dbLink = new mysqli('localhost', 'root', '', 'mydb');
          if(mysqli_connect_errno()) {
              die("MySQL connection failed: ". mysqli_connect_error());
          }
  
          // Gather all required data
          $name = $dbLink-&gt;real_escape_string($_FILES['uploaded_file']['name']);
          $mime = $dbLink-&gt;real_escape_string($_FILES['uploaded_file']['type']);
          $data = $dbLink-&gt;real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']));
          $size = intval($_FILES['uploaded_file']['size']);
  
          // Create the SQL query
          $query = "
              INSERT INTO `file` (
                  `name`, `mime`, `size`, `data`, `created`
              )
              VALUES (
                  '{$name}', '{$mime}', {$size}, '{$data}', NOW()
              )";
  
          // Execute the query
          $result = $dbLink-&gt;query($query);
  
          // Check if it was successfull
          if($result) {
              echo 'Success! Your file was successfully added!';
          }
          else {
              echo 'Error! Failed to insert the file'
                 . "&lt;pre&gt;{$dbLink-&gt;error}&lt;/pre&gt;";
          }
      }
      else {
          echo 'An error accured while the file was being uploaded. '
             . 'Error code: '. intval($_FILES['uploaded_file']['error']);
      }
  
      // Close the mysql connection
      $dbLink-&gt;close();
  }
  else {
      echo 'Error! A file was not sent!';
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Displaying the image</strong></p>
  
  <pre><code>&lt;?php
  $con = mysql_connect("localhost","root","");
  if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("mydb", $con);
  $id = 1;
  if(!isset($id) || empty($id) || !is_int($id)){
       die("Please select your image!");
  }else{  
  $query = mysql_query("SELECT * FROM file WHERE id='".$id."'");
  $row = mysql_fetch_array($query);
  $content = $row['data'];  
  header('Content-type: image/jpg');
       echo $content;
  }  
  ?&gt;
  </code></pre>
  
  <p>My output is something like this:  ����JFIFHH��C</p>