想要将页面重定向到文件
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;
}
但是这个文件并没有出现在屏幕上,我只在“网络”选项卡上看到了这个文件。
eq:
...file?id=123 // first page run header("Location: " . $url); exit;
并从另一台服务器重定向到页面
...download_file?id=123 // status 302
...file.pdf // status 302
...file.pdf // status 200
最后一页的页眉
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
为什么它不在屏幕上显示文件?为什么它不能开始下载?工具中只有信息(选项卡网络)
发布于 2020-12-30 23:17:17
没有在页面上显示文件,因为您需要更改页面的标题来显示它,这可能不是nginx的问题,而是您的PHP (因为我们没有太多的代码来分析您所询问的这种情况)。
But if you check this topic here on StackOverflow you'll see a example to show a PDF.
无论如何,我鼓励你修改你的问题,试着给我们更多的解释和一些代码示例,让我们分析它,给你一个更简洁的答案。
发布于 2020-12-31 20:25:02
正如我所写的,问题已经解决了,问题只是chrome,冲突的问题。
"@PaoloVeronelli -当网站通过HTTPS加载时,如果通过HTTP提供服务,Chrome会阻止加载静态内容。可能看起来Firefox不这样做。- Frederik Feb 14 '15 at 15:51“
$url = str_replace('http://', 'https://', $url);
header("Location: " . $url);
exit;
感谢大家的帮助
https://stackoverflow.com/questions/65509191
复制相似问题