title: How can I download file in codeigniter?
body: <p>I am trying to download file in my codeigniter web application using javascript and codeigniter controller, it shows the file contents in ASCII format but not download the file directly</p>
  
  <p><strong>view.php</strong></p>
  
  <pre><code>&lt;a href="javascript:prd_download(this)"&gt;Download&lt;/a&gt;
  
  &lt;img src="&lt;?php echo site_url()."/../images/uploads/".$jobno."/thumb_".$prd_row-&gt;filename; ?&gt;" alt="Loading Image..." &gt;
  
  &lt;input type="checkbox" name="img_check" id="img_check" class="img_check" image="&lt;?php echo $prd_row-&gt;filename ?&gt;"&gt;
  
  
  &lt;script type="text/javascript"&gt;
  function prd_download(ele)
  {   
      var selected_images = $(".img_check:checked");
  
      var job_no = $("#product_table").attr("jobno");
  
      var image_name = new Array();
  
      for(i = 0; i &lt; selected_images.length; i++)
      {
          image_name[i] = $(selected_images[i]).attr('image');
      }
  
          $.get('&lt;?php echo site_url('project_controller/file_download') ?&gt;', {file_name : image_name, jobno : job_no});
  }
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>controller.php</strong></p>
  
  <pre><code>function file_download()
      {
          $url_para = $_GET['file_name'];
          $job_no = $_GET['jobno'];
          $this-&gt;load-&gt;helper('download');
          $data = file_get_contents(site_url().'/../images/uploads/'.$job_no."/".$url_para[0]);
          $name = 'myphoto.jpg';
  
          force_download($name, $data);
  }
  </code></pre>
  
  <p>I had tried by changing path also, but its not working...</p>