2011-05-25 165 views
2

以下JSP页面摘录显示'content-type'和'content-disposition'设置。该页面将向用户提供一个HTML表格,该表格可以将 导入到Excel中。Safari忽略MIME类型

Chrome,Firefox,IE按预期工作,显示如下设置。 OS X上的Safari Snow Leopard将.html添加到下载的文件中,导致report.xls.html。有没有可用的解决方法将Safari带入正轨?

<%@ 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" content="attachment; filename=report.xls"> 

回答

1

我送这些报头和一个CSV文件和Safari浏览器下载它作为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 
1

周围添加为我的文件名固定的东西报价在Safari/PHP。

1

这一个工作,我让Safari浏览器的行为:

@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 

Idiot-proof, cross-browser force download in PHP两者 - 的问题所要求的不同略有不同的事情,但答案可能是相似,足以考虑标志着其视为重复...

+1

这帮了我一大堆!谢谢。 – 2014-09-17 14:02:09