I have a little function, that creates .xls document(using PHPexcel) and then sends it to php://output. Then user download it.
Everything works fine, except that safari on mac os x adds .html extension for some reason.
So the resulted file is named report.xls.html. Content is ok, but it is annoying to the users.
How can I resolve this?
Here is part of my code:
$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');
I had the same problem
Resolved with exit; at the end of the script
$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;
You can try this header:
header('Content-type: application/ms-excel');
or check http://www.solutionoferror.com/php/phpexcel-not-downloading-in-mobile-safari-81107.asp .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With