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但仍然不完全理解错误消息.
解决方法:
fopen失败并返回false.
false不是资源,因此是警告.
在将其作为类似资源的参数注入之前,最好测试$fp:
if(($fp = fopen($file, "r"))) {
[...]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。