title: Download file from server to clients system via php
body: <p>I am using following script to download a file via PHP:</p>
  
  <pre><code>header('Content-Type: application/octet-stream');
      header('Content-Disposition: attachment; filename=sale.csv');
      header("Content-Transfer-Encoding: binary");
      header('Expires: 0');
      header('Pragma: no-cache');
      header("Content-Length: ".filesize($CSVFileName));
          readfile($CSVFileName);
  </code></pre>
  
  <p>$CSVFilename value is "/home/demo/public_html/testwordpress/csv/sale.csv"
  Also tried header("Content-type: text/csv");</p>
  
  <p>Somehow it is not downloading the csv file given on the path. It is downloading source code of the page in csv. 
  Here is the code i am getting:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;!--[if IE 6]&gt;
  &lt;html id="ie6" lang="en-US"&gt;
  &lt;![endif]--&gt;
  &lt;!--[if IE 7]&gt;
  &lt;html id="ie7" lang="en-US"&gt;
  &lt;![endif]--&gt;
  &lt;!--[if IE 8]&gt;
  &lt;html id="ie8" lang="en-US"&gt;
  &lt;![endif]--&gt;
  &lt;!--[if !(IE 6) | !(IE 7) | !(IE 8)  ]&gt;&lt;!--&gt;
  &lt;html lang="en-US"&gt;
  &lt;!--&lt;![endif]--&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8" /&gt;
  &lt;meta name="viewport" content="width=device-width" /&gt;
  &lt;title&gt;Call Details | Test&lt;/title&gt;
  &lt;link rel="profile" href="http://gmpg.org/xfn/11" /&gt;
  </code></pre>
  
  <p>Please advise</p>