I'm using PHPExcel to generate Excel files on the fly within my PHP application. I'm using the Excel2007
format.
When a user visits the URL that creates and forces the download of the Excel file, everything works great in all browsers except for mobile Safari (iPhone and iPad).
Here are my headers and the readfile
method:
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-disposition: attachment; filename=' . $file_name . '.xlsx;');
header('Content-Length: ' . filesize($path_to_file . '.xlsx'));
readfile($path_to_file . '.xlsx');
When I browse in mobile Safari to the URL that is supposed to download the .xlsx file I can actually see the tabs representing each worksheet of the file, but I don't see the actual data like so:
Furthermore, there are two additional weird behaviors I'm encountering with this:
- If I download this file on a desktop browser and email it to myself and open it with the Mail app in iOS, the file displays correctly.
- If I then take that attachment from the Mail app in iOS and import into, say, Dropbox, it does NOT display properly (it displays the same as the screenshot above).
- In Chrome, the file downloads properly and opens in Excel or even Numbers as expected, but in the console I see this message:
Resource interpreted as Document but transferred with MIME type application/vnd.ms-excel:
Also, per the PHPExcel documentation, in place of readfile
I have also tried:
$objWriter->save('php://output');
That, however, produces an error in mobile Safari that reads:
OfficeImportErrorDomain Error 912
To eliminate the Content-type
as being the issue I've experimented by adjusting the Content-type
to other values (such as application/vnd.ms-excel
or even application/download
). Unfortunately (though not surprisingly) those don't work either.
Any guidance is greatly appreciate.