title: Download a file from database or save folder in codeigniter
body: <pre><code>$data = 'Here is some text!';
  $name = 'mytext.txt';
  
  force_download($name, $data);
  </code></pre>
  
  <p>This is simple bownload code bit I need to download from database or my save path folder.</p>
  
  <p>I need a complete code in MVC codeigniter framework.<br>
  I upload a file in a database and a given path folder  i make a online job portal project of my final degree  i want to download a CV or file  but i cant to it plz help me .how i can download file from a database or a save folder.</p>
  
  <p>and this code is not working plz send me complete code with model view controller.</p>
  
  <pre><code>function download($fid){
      $query= $this-&gt;db-&gt;get_where('files',array('fid' =&gt; $fid));
  
  $row = $query-&gt;result();
  header("Content-Type: ". $row[0]-&gt;type);
  header("Content-Length: ". $row[0]-&gt;size);
  header("Content-Disposition: attachment; filename=". $row[0]-&gt;name);
  
  // Print data
  echo $row[0]-&gt;content;
  
  //Free the mysql resources
  mysql_free_result($result);
  //redirect('index.php/files/search/'.$fid);
   }
  </code></pre>