我们有一个按钮,当我们点击那个按钮时,所有数据进入csv文件并下载此csv文件。 csv文件创建,但下载的代码不工作下载csv文件
$fp = fopen("file\customer-list.csv", "w");
fileName = "file\customer-list.csv";
$filePath = "file\customer-list.csv";
$fsize = filesize("file\customer-list.csv");
if(($_POST['csv_download_list']) == "cm")
{
fwrite($fp, $csv);
fclose($fp);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment; filename=\"$fileName\"");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Length: ' . filesize($filePath));
ob_clean();
flush();
$file = @fopen($filePath,"rb");
if ($file) {
while(!feof($file)) {
print(fread($file, 1024*8));
flush();
}
@fclose($file);
}
exit;
为什么你在你的文件中这么多的变数卢金周围。反正..我认为这个http://stackoverflow.com/questions/1487774/generating-csv-file-and-then-forcing-the-file-to-download应该可以解决你的问题。 – Saurabh
您也可以选择退出.. http://php.net/manual/en/function.readfile.php – Saurabh
如果有可接受的答案,请将其标记为答案。 –