Safari ignoring mime type
The following extract from a JSP page shows the 'content-type' and 'content-disposition' settings. The page shall provide the user with an HTML table, that can be imported to Excel.
Chrome, Firefox, IE work as expected with the settings shown below. Safari on OS X Snow Leopard adds a .html
to the downloaded file resulting in report.xls.html
. Is there a workaround available that brings Safari on track?
<%@ page session="false" contentType="application/vnd.ms-excel;charset=utf-8"%>
...
<meta name="content-type" content="application/vnd.ms-excel;charset=utf-8"></meta>
<meta name="content-disposition" conten开发者_StackOverflow社区t="attachment; filename=report.xls">
I am sending these headers and for a csv file and safari downloads it as report.csv
Pragma: public
Expires: 0
Cache-Control: must-revalidate, post-check=0, pre-check=0
Cache-Control: private
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="report.csv";
Content-Transfer-Encoding: binary
Adding the quotes around the filename fixed things for me in Safari / PHP.
This one worked for me to get safari to behave:
@ob_end_clean(); //turn off output buffering to decrease cpu usage
// required for IE
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="download.csv"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
header('Cache-control: no-cache, pre-check=0, post-check=0');
header('Cache-control: private');
header('Pragma: private');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // any date in the past
Taken from Idiot-proof, cross-browser force download in PHP - the questions are asking for different slightly different things, but the answers might be similar enough to consider marking this as a duplicate...
精彩评论