2016-09-22 51 views
1

我有一個用於下載CSV文件的按鈕。 該文件似乎下載正常,但是,我收到以下警告。 此警告似乎只出現在chrome中。將資源解釋爲文檔,但使用MIME類型應用程序傳輸/ csv

資源解釋爲文獻但與MIME類型application/CSV轉移:

這是我設置CSV標題。

/** 
* Set the PHP mime header 
* 
* This will overwrite any previous headers 
* 
* @param string $header any custom headers that need to be set 
* 
* @return void 
* @access public 
*/ 
function setHeader($header='') 
{ 
    if ($header) { 
     // set custom headers 
     header($header); 
    } else { 
     header('Content-Type: application/csv'); 
     header('Content-Disposition: attachment; filename="'.$this->_filename.'";'); 

     //This is known that Internet Explorer has problems with SSL connection (https). 
     //http://support.microsoft.com/default.aspx?scid=kb;en-us;812935 
     //http://support.microsoft.com/default.aspx?scid=kb;en-us;316431 
     // do not send no cache header in https for IE 

     // get protocol information 
     $url_info = parse_url(current_url()); 
     $protocol = (isset($url_info['scheme'])) ? $url_info['scheme'] : NULL; 
     $using_ie6_8 = isset ($_SERVER['HTTP_USER_AGENT']) ? preg_match('/(MSIE\s[0-8]+\.)/', $_SERVER['HTTP_USER_AGENT']) : FALSE; 
     if (!is_null($protocol) && $protocol == 'https' && $using_ie6_8) { 
      header('Cache-Control: private, max-age=0, must-revalidate'); 
      header('Pragma: private'); 
      header('Expires: '.gmdate('D, d M Y H:i:s', time()-3600).' GMT'); 

     } 

    } 

}//end setHeader() 

響應頭

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Connection:keep-alive 
Content-Disposition:attachment; filename="submission_log.csv"; 
Content-Type:application/csv 
Date:Thu, 22 Sep 2016 04:59:06 GMT 
Expires:Thu, 19 Nov 1981 08:52:00 GMT 
Pragma:no-cache 
Server:openresty 
Transfer-Encoding:chunked 
X-Content-Type-Options:nosniff 
X-Frame-Options:SAMEORIGIN 

請求頭

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 
Accept-Encoding:gzip, deflate 
Accept-Language:en-US,en;q=0.8 
Cache-Control:max-age=0 
Connection:keep-alive 
Content-Length:6252 
Content-Type:multipart/form-data; boundary=----WebKitFormBoundary4CxCF8KLzdtoGRO2 
Cookie:lastSelectedLinkId=2661; lastSelectedAssetId=2151; SQ_SYSTEM_SESSION=o44hori3h2fcu5ltm29u6rv2k44bq1tu6v3364pdi8jn273scebnjm3lsuik5teasneeh664j98o3ajbur6p39kque68qgjohkktsk3; _ga=GA1.2.545099348.1472451817 
Host:matrixdev.squiz.net 
Origin:http://matrixdev.squiz.net 
Referer:http://matrixdev.squiz.net/_admin/?SQ_BACKEND_PAGE=main&backend_section=am&am_section=edit_asset&assetid=2151&sq_asset_path=70%2C2151&sq_link_path=71%2C2661&asset_ei_screen=log 
Upgrade-Insecure-Requests:1 
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 

回答

0
如果你有內部 <a>鏈接下載CSV文件,添加

「下載」 屬性<a>

+0

如果你想這樣做,請確保你的目標瀏覽器支持*按鈕*屬性(並非所有的都是)! http://caniuse.com/#feat=download –

相關問題