2011-05-25 109 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