Aug 22, 2012 at 3:45 AM
Edited Aug 22, 2012 at 4:07 AM
I'm generating Excel files on the fly within my PHP application. I'm using the
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-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.
- f 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:
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.
By the way, I've posted this issue over at
Stack Overflow as well.