Re: Reading from remote file

From: Date: Sun, 06 Jul 2003 14:20:52 +0000
Subject: Re: Reading from remote file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-154123@lists.php.net to get a copy of this message
This is already fixed in CVS. The entire example is bogus, it should not be using filesize($filename) either. Here's what's in CVS (the manual will be rebuilt sometime in the next week): <?php $handle = fopen ("http://www.example.com/", "rb"); $contents = ""; do { $data = fread($handle, 8192); if (strlen($data) == 0) { break; } $contents .= $data; } while(true); fclose ($handle); ?> And the whole point is to demonstrate the following note: "When reading from network streams or pipes, such as those returned when reading remote files or from popen() and proc_open(), reading will stop after a packet is available. This means that you should collect the data together in chunks as shown in the example below." Have fun :) Regards, Philip On Sun, 6 Jul 2003, Daniele Baroncelli wrote: > Hi guys, > I am trying to read from a remote file, by using an example reported at the > manual page for the fread function: > > <?php > $handle = fopen ("http://www.php.net/", > "rb"); > $contents = ""; > do { > $data = fread ($handle, filesize ($filename)); > if (strlen($data) == 0) { > break; > } > $contents .= $data; > } > fclose ($handle); > ?> > > > Unfortunately this example is incorrect, as it gives me a parse error. The > mistake should be in the fact that there is a "do" keyword without a > "while". > Would anyone suggest me the correct version? > > Cheers > > Daniele > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#154123) next »