Re: fopen problem, 5 line script

From: Date: Thu, 16 Sep 2004 08:56:10 +0000
Subject: Re: fopen problem, 5 line script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196834@lists.php.net to get a copy of this message
Irrelevant, Warren Mag, the point is that you're trying to use a function (filesize) that uses the stat() system call. This function is not supported using the http wrapper to fopen (because HTTP doesn't support it at all) So regardless of whether you should be using the file name or the handle (it's the name, btw), the call will fail because you're trying to stat() a file which isn't supported. Thus filesize() is failing (with a warning), and fread() is then failing because filesize() returns false, which evaluates to 0. Hope this has made things clearer, if not, a quick check of the manual entries for stat, filesize and Appendix L (http://uk.php.net/manual/en/wrappers.php) may help Cheers chris Vail, Warren wrote:
I thought filesize required the file name, and not the fileptr??? Warren Vail -----Original Message----- From: Curt Zirzow [mailto:php-general@zirzow.dyndns.org] Sent: Wednesday, September 15, 2004 10:17 AM To: php php Subject: Re: [PHP] fopen problem, 5 line script * Thus wrote Mag:
Hi, Can someone tell me what I am doing wrong here please? <?php $fileptr = fopen("http://www.google.com/index.html","r"); $contents = fread($fileptr, filesize($fileptr)); ... This is the error I get: Warning: filesize(): Stat failed for Resource id #1 (errno=2 - No such file or directory) in /home/quickxxx/public_html/tpg/ check- remote.php on line 4 Warning: fread(): Length parameter must be greater than 0. in / home/quickxxx/public_html/tpg/check-remote.php on line
filesize() relies on the fact that the file you opened has support for stat(). the http wrapper does not have such a thing. see: http://php.net/filesize http://php.net/wrappers.http Curt


« previous php.general (#196834) next »