我试图得到一个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'));
但也抛出
错误:未找到文件。
任何想法我能做些什么,以追查问题将是巨大的。我敢肯定,这一定有什么事情我不能看到好看!
钽ँSK
我不相信file_exist()对URL的作品。尝试这样的事情,而不是:
function url_exists($url){
$ccmd = curl_init($url);
curl_setopt($ccmd, CURLOPT_NOBODY, true);
curl_exec($ccmd);
$rtncode = curl_getinfo($ccmd, CURLINFO_HTTP_CODE);
curl_close($ccmd);
if($rtncode == 200){
return true;
}
return false;
}