Re: newbie: contents will not output
| From: | Ernest E Vogelsinger | Date: | Tue, 11 Mar 2003 08:40:50 +0000 |
| Subject: | Re: newbie: contents will not output | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-139104@lists.php.net to get a copy of this message | ||
At 04:22 11.03.2003, Anthony Ritter said:
--------------------[snip]--------------------
>I'm trying to test the following script to display the contents of the
>following URL but it will not output.
>
>Any advice will be greatly appreciated.
>Thank you.
>Tony Ritter
>.......................................................
>
><? $file_handler = fopen("http://www.weather.com",
>"r"); $contents =
>fread($file_handler, filesize($file)); fclose($file_handler); echo
>$contents; ?>
--------------------[snip]--------------------
You cannot stat() (i.e. use filesize()) a remote file, filesize() will
return false making your script read 0 (zero) bytes.
When reading remote files you may consider chunking them:
$fh = fopen('http://www.weather.com',
'r');
if ($fh) {
while ($chunk = fread($fh, 4096))
echo $chunk;
fclose($fh);
}
This will work perfectly (if url-fopen-wrapper is enabled in your build
anyway).
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/