title: Saving images into database
body: <p>I'm trying to save images in a mysql database. It saves binary code into the table, but its corrupt and i can't display it. Also the size of the database field is bigger than the original file. Is there anything wrong in my code or in the approach im having. </p>
  
  <p>I know thats its not a good practice to store images in a database, but im not in the position to decide it.</p>
  
  <pre><code>  &lt;div class="box-body"&gt;
               &lt;h3&gt;Bilder&lt;/h3&gt;
                &lt;form id="image_form"&gt;
                     &lt;input type="file" name="frame" id="file_name" /&gt;
                     &lt;input type="submit" value="Save"&gt;
                 &lt;/form&gt;
       &lt;/div&gt;
  
   $('#image_form').on("submit",(function (e) {
              e.preventDefault();
              $.ajax({
                  type: 'POST',
                  url: './index.php?action=585',
                  data: new FormData(this),
                  contentType: false,
                  cache: false,
                  processData: false,
                  beforeSend: function (a) {
                      //a.overrideMimeType('image/jpeg; charset=UTF-8');
                  },
                  success: function (data) {
                      console.log(data);
                  },
                  error: function () {
                      location.reload();
                  }
              });
          }));
  </code></pre>
  
  <p>Back-End</p>
  
  <pre><code>//Get the content of the image and then add slashes to it
  $tmpName = $_FILES['frame']['tmp_name'];
  $fp = fopen($tmpName, 'r');
  $data = fread($fp, filesize($tmpName));
  $data = addslashes($data);
  
  var_dump($data);
  
  $imagetmp = $data;
  
  AccountDAO::updateResImages($imagetmp, $imagetmp, $imagetmp, $_SESSION['customer']-&gt;id);
  </code></pre>
  
  <p>Database </p>
  
  <pre><code>public static function updateResImages($img1, $img2, $img3, $customerid){
      $db = new MySQLDatabase();
      $sql = "UPDATE customer SET online_res_bild1 = ?, online_res_bild2 = ?, online_res_bild3 = ? WHERE customer_id = ? ";
      $rs = $db-&gt;executeQuery($sql, 'sssi', $img1, $img2, $img3, $customerid);
      $db-&gt;close();
      return 1;
  }
  </code></pre>