【发布时间】:2013-04-17 18:54:46
【问题描述】:
我正在尝试通过浏览器下载 CSV 文件。该脚本部分工作,因为到目前为止我设法在屏幕上显示 CSV,但下载没有开始。
这是我目前尝试过的:
if(isset($currency)) {
header("Content-Type: application/csv");
header("Content-Disposition: attachment;Filename=Pricelogs.csv");
ob_clean();
$filename = "/tmp/".uniqid().".csv";
exportCSVFile($filename, $currency, $country, $provider);
readfile($filename);
//unlink("'".$filename."'");
} else {
echo "ERR_USERNAME_PASSWORD";
exit();
}
我已经阅读了常见问题解答中的所有此类问题并尝试过,但它只能在浏览器上打开,而不是下载。
我还使用了带单引号的标题。
我也试过header("Content-Type: text/csv");
另外:
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$filename."\";" );
header("Content-Transfer-Encoding: binary");
【问题讨论】:
标签: php download force-download