Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari adding .html to download

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');
like image 952
Davinel Avatar asked Oct 14 '13 15:10

Davinel


2 Answers

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;
like image 53
BenJsno Avatar answered Sep 18 '22 12:09

BenJsno


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 .

like image 37
sourabh kasliwal Avatar answered Sep 20 '22 12:09

sourabh kasliwal