Download file from server to clients system via php


Staff member
I am using following script to download a file via PHP:

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));

$CSVFilename value is "/home/demo/public_html/testwordpress/csv/sale.csv"
Also tried header("Content-type: text/csv");

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:

<!DOCTYPE html>
<!--[if IE 6]>
<html id="ie6" lang="en-US">
<!--[if IE 7]>
<html id="ie7" lang="en-US">
<!--[if IE 8]>
<html id="ie8" lang="en-US">
<!--[if !(IE 6) | !(IE 7) | !(IE 8)  ]><!-->
<html lang="en-US">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Call Details | Test</title>
<link rel="profile" href="" />

Please advise