Why are PHPExcel files broken when saved remotely?

I am having a strange problem with PHPExcel deleting files remotely.

This is the code I use to download the browser:

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 that I download this way cannot be opened by either LibreOffice or Microsoft Office .

BUT, if I replace all these lines with this single line:

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

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

What can cause this and how to fix it?

+3
source share
1 answer

"", ? PHP, xls ,

0

All Articles