警告feof()希望参数1成为资源 [英] warning feof() expects parameter 1 to be resource
本文介绍了警告feof()希望参数1成为资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的错误日志失控,出现以下错误
warning feof()希望参数1成为资源
和
warning fread()期望参数1为资源
负责的代码是
<?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(); //这并不重要。
$ fp = fopen($ file,r);
while(!feof($ fp)){
echo fread($ fp,65536);
flush(); //这对于大量下载是必不可少的
}
fclose($ fp);
?>
我使用这个代码进行头文件下载,但是现在已经出错了 - 在任何人询问我已经尝试过我尝试过google但仍然不完全明白错误信息。
解决方案
fopen失败并返回false。
false不是资源,因此是警告。
最好在将$ fp注入资源类型的参数之前测试$ fp:
if(($ fp = fopen($ file,r))){
/ pre>
[...]
}
My error logs are getting out of control with the two below errors
warning feof() expects parameter 1 to be resource
and
warning fread() expects parameter 1 to be resource
The bit of code responsible is
<?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); ?>
I used this code for header downloads but its freaking out right now - before anyone asks what I have tried, I tried google but still don't fully understand the error message.
解决方案fopen fails and returns false. false is not a resource, thus the warning.
You'd better test $fp before injecting it as a resource-like argument:
if(($fp = fopen($file, "r"))) { [...] }
这篇关于警告feof()希望参数1成为资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文