【问题标题】:Google Chrome errors while exporting XLS file using PHP使用 PHP 导出 XLS 文件时出现 Google Chrome 错误
【发布时间】:2012-06-02 16:01:03
【问题描述】:

我一直在使用 PHP 脚本将数据从我的数据库 (mysql) 导出到 XLS 文件。

虽然文件导出过程在 Firefox 和 IE 上运行良好。

我在尝试使用 Google Chrome 导出时遇到错误。

谷歌浏览器错误是

    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.

我需要一些帮助。

谢谢

【问题讨论】:

  • HTTP 响应标头有问题。使用 Fiddler 捕获 HTTP 标头并在此处发布。
  • 发生在我身上。通过从文件名中删除逗号来修复它
  • 另一个答案将header("Content-Disposition: attachment; filename={$file}");更改为header("Content-Disposition: attachment; filename=\"{$file}\"");
  • 在我的情况下,这样做会导致此处描述的错误:stackoverflow.com/questions/6530569/…

标签: php google-chrome


【解决方案1】:

我在 PHP 导出代码的标题部分发现了我的问题。不正确和正确的行如下:

不正确

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

正确

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

修正是在 attachment;filename

之间添加一个空格

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题。然而,仅很少出现。原因相似但不完全相同。

    不正确

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

    正确

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

    $filename 有时包含空格,导致提及 Chrome 错误。

    【讨论】:

      【解决方案3】:

      我也遇到了同样的问题。下载名称中带有逗号的文件时,它说“收到了重复的标头”,并且仅在 chrome 中。在 Firefox 中没问题。之后,我将代码从
      header("Content-Disposition: attachment; filename=$myfilename"); 更改为 header("Content-Disposition: attachment; filename=\"$myfilename\""); 效果很好。希望它对你有用。

      【讨论】:

      • 谢谢,我有 2700 个页面,它在 Chrome 中的工作率约为 96%,但在其他 4% 中没有,但它在 Edge 中 100% 的时间都有效。
      【解决方案4】:

      试试这个可能对你有帮助, header('Content-Disposition: attachment; filename="'.$file_name.'"');

      而不是

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

      【讨论】:

        猜你喜欢
        • 2012-05-30
        • 1970-01-01
        • 2011-11-01
        • 1970-01-01
        • 2017-02-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多