? Supplied argument is not a valid File-Hand resource ?

Hey guys, I am am new to php and mySQL stuff and am trying my hardest to understand what is going on with my script.

Can someone please explain to me what
“Warning: Supplied argument is not a valid File-Handle resource” Means?

I know this has to be something specific but I’ve searched forever on google and forums and not found any info.

My script goes to a feed file and apears to read its contents but I dont know what the “10000” is for :cry:

here is my examples:

problem code- Line 02: $url = "/var/www/sites/mysite.com/forums/src/feed.php"; Line 54: $responsehandle = fopen($url,"r"); Line 56: $botresponse = fread($responsehandle,10000); Line 58: fclose($responsehandle);

This is the Feed file it opens:


<?php if (isset($HTTP_GET_VARS["post"]) AND isset($HTTP_GET_VARS["id"]) AND ereg("^[0-9]+$",$HTTP_GET_VARS["id"]) ) { include "respond.php"; $numselects=0; $botresponse=reply($HTTP_GET_VARS['post'],$HTTP_GET_VARS["id"],1); echo $botresponse->response; exit; } ?>[/code]

When this script is executed, it returns:

Warning: fopen(“http://cgi.mysite.com/forums/feed.php?id=3&post=”, “r”) - Success in /var/www/sites/mysite.com/forums/sources/invbot.php on line 54

Warning: Supplied argument is not a valid File-Handle resource in /var/www/sites/mysite.com/forums/sources/invbot.php on line 56

Warning: Supplied argument is not a valid File-Handle resource in /var/www/sites/mysite.com/forums/sources/invbot.php on line 58

I think this means that it successfully opened the file but the argument on line 56 (the “10000”) is causing it problems or maybe the “$numselects=0” in my feed file but I am no expert at this.

Does anyone know anyone who can explain what is happening here?

Thank you in advance for any help!


I dont use the file functions too much, but I think line 56 should be:

$botresponse = fread($responsehandle, filesize($url)); 

Try that.

Hi and Thanks for the reply!!!

This project was for a A.I. chatbot that I was incorperating into my forum. I always had this error when I asked her a question that required her to search the web (or so I am thinking)

I updated her “knowledge base” last night and for some reason it doesnt give me that error anymore.

I have also requested help from my host and they only could give me info on the actual fopen() fclose() commands which help out a lot too.

I havent attempted your code yet but if this problem occurs in the future I will most definetely try it and provide feedback!

This is the info my host explained to me:

When you get that error, it means that the fopen() function has failed.

Further more the php is not meant to be used to open urls like that,
they only functions on static links not dynamic content.
You can get more data on both the usage of functions and php itself
by reading the official manuals at http://www.php.net

In this case you may want to read the documentation for fopen at
http://www.php.net/fopen and the following:


the f* file access functions are part of the core php install and can
not be unsupported by the system; However what you are trying to do
is make use of remote file streams and that is not always supported
due to security concerns.

fopen() is a wrapper of the C function used to directly access files
as data, not to access them as a interpreted script; The reason your
script is failing is because the function is being used incorrectly.

You guys prolly dont need this info since you may know it already, but hopefully someone else will have this error one day and stumble across this post.
I know if I would have found this data a couple days ago - I would been So happy :lol:

But thank you once again for your info on my problem! I will let you know if I need to use that script and how it does.


Sponsor our Newsletter | Privacy Policy | Terms of Service