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));
readfile($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">
<![endif]-->
<!--[if IE 7]>
<html id="ie7" lang="en-US">
<![endif]-->
<!--[if IE 8]>
<html id="ie8" lang="en-US">
<![endif]-->
<!--[if !(IE 6) | !(IE 7) | !(IE 8) ]><!-->
<html lang="en-US">
<!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Call Details | Test</title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
Please advise