title: Code Igniter - How to save images into database
body: <p>I'm making use of codeIgniter to upload files into folders in the server. Now I also want to save the data into the database, what do I need in order to get the raw data and then save it into the database?</p>
  
  <p>Here's the model for saving files:</p>
  
  <pre><code>&lt;?php
  class files extends ci_Model{
      function saves($filename, $filedata, $post_id){
          $this-&gt;db-&gt;query("INSERT INTO tbl_files SET file_data='$filedata', filename='$filename', postid='$post_id'");
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Here's how I call it from the upload controller:</p>
  
  <pre><code>$filename = $data['upload_data']['file_name'];
  $file_data = file_get_contents($data['upload_data']['file_name']);
  
  $this-&gt;load-&gt;model('files');
  $this-&gt;files-&gt;saves($filename, $file_data, 'ID1');
  </code></pre>
  
  <p>Table Structure:</p>
  
  <ul>
  <li>file_data (LONG BLOB) </li>
  <li>filename (VARCHAR)</li>
  </ul>