我尝试从PHP数组创建CSV文件,但未创建。其仅显示消息。
$filename = "export_data" . rand(1,100) . ".csv";
//$export_data = unserialize($_POST['export_data']);
// file creation
$file = fopen($filename,"w");
foreach ($error_array as $line){
$array_trimmed = array_map("trim", $line);
fputcsv($file,$line);
}
fclose($file);
// download
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=".$filename);
ob_end_clean();
header("Content-Type: application/csv; ");
readfile($filename);
// deleting file
unlink($filename);
exit();
它是我的数组
Array
(
[0] => Array
(
[0] => LAN
[1] => CATEGORY
[2] => TYPE
)
[1] => Array
(
[0] => 123456789114545
[1] => EMI Related - Bounce Reason
[2] => Request
[3] => lan number not valid
)
[2] => Array
(
[0] => 12345678911454
[1] => EMI Related - Bounce Reason
[2] => Request
[3] => lan number not valid
)
)