【发布时间】:2015-11-08 20:36:39
【问题描述】:
所以我有一个 PHP 下载的小 PHP 条件,它已经工作了好几个星期,然后突然我注意到它停止工作了。
用户获得的是一个 0kb 的文件,而不是下载文件。
我检查了 URL,它仍然按预期工作。
这里是代码
if ($refer == 'stackoverflow.com' || $refer == 'dev.stackoverflow.com') {
$fichero = $downloadUrl;
if ($fichero) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fichero));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fichero));
ob_clean();
flush();
readfile($fichero);
exit;
} else {
die("The File $fichero does not exist");
}
} else {
die("Sorry you must start the download from the website");
}
现在我知道它符合条件,因为我没有收到任何 die 语句,并且该文件仍然作为下载提供。这似乎在 Chrome 和 IE(Edge) 中都出现了问题。我一直在阅读有关标头的内容,我发现与此问题相关的唯一文档是我设置为 0 的 expires 设置。
我在这里错过了一个简单的技巧吗?
非常感谢!
【问题讨论】:
-
var_dump(filesize($fichero));输出什么? -
感谢您的回复,我没想到要转储 var。所以我把它卡在 if $fichero) - boolean false 中。所以这是我的问题
-
有趣的是,我可以在 apache 错误日志中看到 filesize(): stat failed for URL,但在浏览器中发布的 URL 立即生效。
-
我认为可能是权限问题。