warning feof() expects parameter 1 to be resource

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

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

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.

回答1:

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"))) {     [...] } 


回答2:

I recently encountered this problem. The code ran perfectly on my local environment. But when it was loaded to the server, I got the message discussed in this thread. At the end, the problem was that the server is case-sensitive on file names, while my local environment is not. After having corrected the file name, everything started to work.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!