当我们单击该按钮时,我们有一个按钮,所有数据都进入 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;