开发者

Why are PHPExcel files broken when saving remotely?

开发者 https://www.devze.com 2023-03-13 10:33 出处:网络
I\'m having a weird issue with PHPExcel saving files remotely. This is the 开发者_高级运维code I use for browser download:

I'm having a weird issue with PHPExcel saving files remotely.

This is the 开发者_高级运维code I use for browser download:

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="filename.xls"');
header('Cache-Control: max-age=0');
$objWriter->save('php://output');

Unfortunately, every file I download this way cannot be open by neither of LibreOffice and Microsoft Office.

BUT if I replace all those lines with this single line:

$objWriter->save(str_replace('.php', '.xls', __FILE__));

The file can be opened and all data/formatting is perfect. The only problem is that it saves it on the server, right next to the controller that generates it.

What could cause this and how to fix it?


when you save it 'remotely', what extension does the file has? if it is PHP, you might want to try to change its extension to xls manually and see if it works

0

精彩评论

暂无评论...
验证码 换一张
取 消