【发布时间】:2019-07-05 09:31:25
【问题描述】:
我正在尝试获取一个 zip 文件以自动下载:
$attachment_location = "https://dev.com/daily/updates/com_prog_v1_8_0.zip";
if (file_exists($attachment_location)) {
header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
header("Cache-Control: public"); // needed for internet explorer
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: Binary");
header("Content-Length:".filesize($attachment_location));
header("Content-Disposition: attachment; filename=com_prog_v1_8_0.zip");
readfile($attachment_location);
die();
}
我尝试在浏览器中进行链接,文件下载没有问题。我不确定如何调试它。据我所知,这是对的。我期待运行这个文件(和 index.php 文件)并让它开始下载文件。我仔细看了其他帖子,但无法找出问题所在。
我也试过了
file_put_contents("com_prog_v1_8_0.zip", fopen("https://dev.com/daily/updates/com_prog_v1_8_0.zip", 'r'));
但这也会引发
错误:找不到文件。
任何我能做些什么来追踪问题的想法都会很棒。我敢肯定它一定是我看不到的东西!
谢谢
【问题讨论】:
-
你是如何重定向的?
-
嗨我试过 curl 但它不起作用 - 同样的错误
-
你是如何重定向的?
-
我只是使用上面的代码来下载文件
标签: php redirect header location