Safari添加.html下载

Dav*_*nel 13 php safari xls download

我有一个小函数,它创建.xls文档(使用PHPexcel),然后将其发送到php://输出.然后用户下载它.
一切正常,除了mac os x上的safari由于某种原因增加了.html扩展名.
因此,生成的文件名为report.xls.html.内容没问题,但对用户来说很烦人.

我该如何解决这个问题?

这是我的代码的一部分:

$filename = 'report.xls';

header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.$filename.'"'); 
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save('php://output');
Run Code Online (Sandbox Code Playgroud)

小智 30

我有同样的问题

退出决定; 在脚本的最后

$filename = 'report.xls';
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.$filename.'"'); 
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save('php://output');
exit;
Run Code Online (Sandbox Code Playgroud)

  • 感谢上帝,这个解决方案有效,但我可以问为什么`退出;`解决问题? (3认同)