简体   繁体   English

使用PHP导出XLS文件时出现Google Chrome错误

[英]Google Chrome errors while exporting XLS file using PHP

I've been using a PHP script to export data from my database (mysql) to a XLS file. 我一直在使用PHP脚本将数据从我的数据库(mysql)导出到XLS文件。

While the file export process is working fine on Firefox and IE. 虽然文件导出过程在Firefox和IE上运行良好。

I am getting errors when trying to export using Google Chrome. 尝试使用Google Chrome导出时出错。

The Google Chrome error is 谷歌浏览器错误是

    Duplicate headers received from server

The response from the server contained duplicate headers. This problem is generally the result of a misconfigured website or proxy. Only the website or proxy administrator can fix this issue.

Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple distinct Content-Disposition headers received. This is disallowed to protect against HTTP response splitting attacks.

I need some assistance on this. 我需要一些帮助。

Thanks 谢谢

I've found out what my problem was in the header section of the PHP export code. 我已经在PHP导出代码的标题部分找到了我的问题。 The incorrect and correct lines are as follows: 错误和正确的行如下:

Incorrect 不正确

header("Content-Disposition: attachment;filename=\"".$this->filename."\"");

Correct 正确

header("Content-Disposition: attachment; filename=\"".$this->filename."\"");

The correction being adding a space between attachment; 修正是在附件之间增加一个空格; and filename 文件名

Hope this helps. 希望这可以帮助。

I had this same problem. 我有同样的问题。 However appearing only very rarely. 但是很少出现。 Cause was similar but not quite the same. 原因相似但不完全相同。

Incorrect 不正确

header("Content-Disposition: attachment; filename=$filename");

Correct 正确

header("Content-Disposition: attachment; filename=\"$filename\"");

$filename sometimes contained spaces resulting in mentionec Chrome error. $ filename有时包含空格,导致提及Chrome错误。

I also faced the same problem. 我也遇到了同样的问题。 While downloading a file having comma in its name it was saying " duplicate headers received " and it is only in chrome. 在下载名称中包含逗号的文件时,它会说“ 收到重复的标题 ”并且只是在chrome中。 In Firefox it was OK. 在Firefox中没关系。 After that I just changed my code from 之后我只是改变了我的代码
header("Content-Disposition: attachment; filename=$myfilename"); to header("Content-Disposition: attachment; filename=\\"$myfilename\\""); to header("Content-Disposition: attachment; filename=\\"$myfilename\\""); and it worked fine. 它工作得很好。 Hope it will work for you. 希望它能为你效劳。

Try this may help you, header('Content-Disposition: attachment; filename= "'.$file_name.'"' ); 尝试这可以帮助你,标题('Content-Disposition:attachment; filename = “'。$ file_name。'”' );

instead of 代替

header('Content-Disposition: attachment; filename='.$file_name); header('Content-Disposition:attachment; filename ='。$ file_name);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM