title: Insert/view image into/from a MySQL DB
body: <p>I have a problem with inserting images in DB.
  The table has the following structure:</p>
  
  <ul>
  <li>id->INT(3)->autoincrement</li>
  <li>name->VARCHAR(30)</li>
  <li>extension->VARCHAR(10) [maybe too short]</li>
  <li>img->MEDIUMBLOB</li>
  </ul>
  
  <p>The PHP code that insert the image is:</p>
  
  <pre><code>if($_FILES['file']['error']==0){
          $result = is_uploaded_file($_FILES['file']['tmp_name']);
          if(!$result){
              echo "Upload failed";
          }else{
              $type = explode("/", $_FILES['file']['type']);
              $extension = $type[1];
  
              $name = $_FILES['file']['name'];
              $img = $_FILES['file']['tmp_name'];
              $img = file_get_contents($_FILES['file']['tmp_name']);
              $img = addslashes ($img);
          }
  
          $sql = "INSERT INTO images (name, extension, img) VALUES ('$name', '$extension', '$img')";
          $result = $mysqli-&gt;query($sql);
          if($result){
              echo "insertion was successful";
          }else{
              echo "insertion failed: ".$mysqli-&gt;error;
          }
  </code></pre>
  
  <p>And this is how i try to see img:</p>
  
  <pre><code>$sql = "SELECT name, extension, img FROM images WHERE id='1'";
  $result = $mysqli-&gt;query($sql);
  if($result){
      $a = $result-&gt;fetch_assoc();
      header ("Content-type: image/".$a['estensione']);
      echo $a['img'];
  
  }else{
      echo "AAAAAAAAA&lt;hr&gt;";
      echo $mysqli-&gt;error;
  }
  </code></pre>
  
  <p>The insertion is Ok, but i can't view the image.
  In addition, there's another way to upload image in Db?</p>