【发布时间】:2019-07-12 09:12:26
【问题描述】:
我的应用程序 (php/phpExcel) 提供了 .csv 文件的下载功能。当我使用 chrome 或 IE 下载文件时一切正常,但是当我使用 Firefox 进行下载时,它会将文件扩展名更改为“.csv.htm”,然后 Excel 会询问如何打开,因为扩展名和文件格式不适合。
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename="csvdownload_'.date("Y-m-d_H_i_s").'.csv');
echo "\xEF\xBB\xBF"; // UTF-8 BOM
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
$objWriter->setDelimiter(';');
$objWriter->setEnclosure('"');
$objWriter->setLineEnding("\r\n");
$objWriter->save('php://output');
【问题讨论】: