【问题标题】:PHP file download are blocked by Chrome due to insecure connection (mixed-content)由于连接不安全(混合内容),Chrome 阻止了 PHP 文件下载
【发布时间】:2021-04-23 17:02:25
【问题描述】:

我有几个项目文件下载不再起作用。这似乎是由于最近的 Chrome 政策变更所致。

下载尝试失败,控制台中出现此错误:

Mixed Content: The site at 'https://example.com/' was loaded over a secure connection, but the file at 'https://example.com/logs_view.php?export=true' was redirected through an insecure connection. This file should be served over HTTPS. This download has been blocked. See https://blog.chromium.org/2020/02/protecting-users-from-insecure.html for more details.

我的文件是通过 PHP 提供的:

header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=".$filename.".xls");  
header("Pragma: no-cache"); 
header("Expires: 0");
echo utf8_decode($export);

似乎这种方法不发送带有 HTTPS 标头的文件......关于如何解决这个问题的任何想法?

您可以在服务器响应标头的标头下方找到:

HTTP/1.1 200 OK
Date: Tue, 19 Jan 2021 11:33:14 GMT
Server: Apache
Expires: 0
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Disposition: attachment; filename=base_changelog_2021-01-19_12-33-14.xls
Content-Length: 899
Keep-Alive: timeout=5, max=92
Connection: Keep-Alive
Content-Type: application/xls

非常感谢您的支持。

【问题讨论】:

  • 这个问题好运吗?我也面临同样的情况\

标签: php google-chrome https http-headers mixed-content


【解决方案1】:

您的代码没有任何问题。 当您重定向到返回文件的 url 时,您在 https 安全连接上尝试从 http 执行此操作。可能你有错误协议的链接。

【讨论】:

    【解决方案2】:

    我找到了一种强制 chrome “升级”下载的方法。

    我在我的 .htaccess 中添加了这个调整,它完成了工作!!!

    <ifModule mod_headers.c>
    Header always set Content-Security-Policy "upgrade-insecure-requests;"
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2013-11-01
      • 2021-05-30
      • 1970-01-01
      • 2016-01-17
      • 2014-01-03
      • 1970-01-01
      相关资源
      最近更新 更多