我有几个项目的文件下载不工作了。这似乎是由于最近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
谢谢你的支持。
本
您的代码没有任何问题。当你重定向到返回文件的url时,你正试图从http做起,而你在https安全连接上。可能您的链接协议错误。
我找到了一种方法来强制chrome升级"下载。
我添加到我的。htaccess这个调整,它做的工作!!
<ifModule mod_headers.c>
Header always set Content-Security-Policy "upgrade-insecure-requests;"
</IfModule>