[英]nginx php download file after redirect not working
想要将页面重定向到文件
function downloadFile($url) {
... // save info to database
$path = ..; // checking if the file is on the local server
if(empty($path) === false) {
// download file from local server - it works
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"". basename($path) ."\"");
readfile($path);
exit;
}
// downloading a file from another server - it does not work, $url is 100% good
header("Location: " . $url);
exit;
}
但该文件未在屏幕上显示,我仅在“网络”选项卡中看到此文件
情商:
...file?id=123 // first page run header("Location: " . $url); exit;
并从另一台服务器重定向到页面
...download_file?id=123 // status 302
...file.pdf // status 302
...file.pdf // status 200
header 最后一页
HTTP/1.1 200 OK
Date: Wed, 30 Dec 2020 15:45:21 GMT
Server: Apache
Last-Modified: Wed, 30 Dec 2020 16:38:38 GMT
ETag: "1a8f32-5b7af7b443bf7"
Accept-Ranges: bytes
Content-Length: 1740594
Content-Disposition: attachment
Content-Type: application/force-download
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
为什么它不在屏幕上显示文件? 为什么它不开始下载? 工具中只有信息(选项卡网络)
没有在页面上显示文件,因为您需要更改页面的标题以显示它,这可能与 nginx 无关,但与您的 PHP 无关(因为我们没有太多代码来分析这种情况你问的)。
但是,如果您在 StackOverflow 上查看此主题,您将看到一个显示 PDF 的示例。
无论如何,我鼓励你编辑你的问题并尝试给我们更多的解释和一些代码示例,以便我们分析它并给你一个更简洁的答案。
解决了,正如我写的,问题只是chrome,冲突的问题
"@PaoloVeronelli - Chrome blocks the static content from loading if it is being served over HTTP when the site is loaded over HTTPS. It could look like Firefox doesn't do this. – Frederik Nielsen Feb 14 '15 at 15:51"
$url = str_replace('http://', 'https://', $url);
header("Location: " . $url);
exit;
感谢大家的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.