资源解释为Document但使用MIME类型application / csv传输

时间:2016-09-22 05:30:41

标签: php google-chrome csv request

我有一个下载CSV文件的按钮。 该文件似乎下载正常,但我得到以下警告。 此警告似乎只出现在chrome中。

  

资源被解释为文档但使用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

1 个答案:

答案 0 :(得分:0)

如果您在<a>内有链接下载csv文件,请添加&#34;下载&#34;属性为<a>