title: Error Downloading xls file form CI PHP
body: <p>My model(action.php)</p>
  
  <pre><code>class action extends CI_Model{
  
  public function __construct(){
      $this-&gt;load-&gt;database();
  }
  
  public function get_data(){
    $query =$this-&gt;db-&gt;query('SELECT * FROM data');
    return $query-&gt;result();
  }
  
  }
  </code></pre>
  
  <p>My.Controller(Index_cont.php)</p>
  
  <pre><code>public function report()
  {
    $data = array(
      "user"=&gt; $this-&gt;action-&gt;get_data());
               //var_dump($data); die();
  
    $filename ="comment.xls";
    $contents = $this-&gt;load-&gt;view("Komentar", $data);
    header('Content-type: application/ms-excel');
    header('Content-Disposition: attachment; filename='.$filename);
    echo $contents;
  }
  </code></pre>
  
  <p>My View(index.php)</p>
  
  <pre><code>&lt;form class="" action="&lt;?php echo base_url('index_cont/report'); ?&gt;" method="post"&gt;
      &lt;button class="btn btn-primary" name="submit"  type="submit"&gt; Download Report&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The problem is my code just view <code>Komentar.php</code> (<code>$contents = $this-&gt;load-&gt;view("Komentar", $data);</code>)  and not execute download xls code. If I remove that line, it can download blank xls file. I want to download my data in <code>Komentar.php</code> not just blank page.</p>
  
  <blockquote>
  <pre><code>Response Header
  Request URL: http://localhost:8000/tekinf-ci/index_cont/report
  Request Method: POST
  Status Code: 500 Internal Server Error
  Remote Address: [::1]:8000
  Referrer Policy: no-referrer-when-downgrade
  Cache-Control: no-store, no-cache, must-revalidate
  Connection: close
  Content-Length: 1924
  Content-Type: text/html; charset=UTF-8
  Date: Tue, 10 Apr 2018 13:59:44 GMT
  Expires: Thu, 19 Nov 1981 08:52:00 GMT
  Pragma: no-cache
  Server: Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9
  Set-Cookie: ci_session=ap0r8obbc47nqqcbt1ehrg0u5bffeg17; expires=Tue, 10-Apr-2018 15:59:45 GMT; Max-Age=7200; path=/; HttpOnly
  X-Powered-By: PHP/7.0.9
  </code></pre>
  </blockquote>