【发布时间】:2013-05-14 20:43:35
【问题描述】:
我的错误日志因以下两个错误而失控
warning feof() expects parameter 1 to be resource
和
warning fread() expects parameter 1 to be resource
负责的代码是
<?php
$file = '../upload/files/' . $filex;
header("Content-Disposition: attachment; filename=" . urlencode($file));
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . filesize($file));
flush(); // this doesn't really matter.
$fp = fopen($file, "r");
while (!feof($fp)) {
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
?>
我使用此代码进行标题下载,但现在它吓坏了 - 在有人问我尝试过什么之前,我尝试了 google,但仍然不完全理解错误消息。
【问题讨论】:
-
这对于服务器可以在没有 PHP 的情况下处理的事情来说似乎需要做很多工作。
-
fopen出错时返回FALSE。 -
表示文件指针无法访问文件。确保文件位于该位置,并且运行脚本的用户对其具有读取权限。我没有看到 $filex 被分配到任何地方,所以请确保它已被分配。
-
@NullUserException: 如果文件在 webroot 之外,则不会。
-
相关的指针是:如果您正在尝试在文档根目录之外提供文件,try X-Sendfile。
标签: php error-handling