Re: problem with fread
| From: | Dan Hardiker | Date: | Thu, 01 Jan 1970 00:00:00 +0000 |
| Subject: | Re: problem with fread | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-96382@lists.php.net to get a copy of this message | ||
> i have a question about the fread() function.
> i want to read data from a webserver url, which i don't know the exact
> size of, i only know that it varies.
You dont actually give the size of the file, you give the size of the block
you want to pull. For example:
<?php
$output = ""; // Clear output
$url = "http://whatever.com/file.html"; // whatever you
wanna pull from
if ($fp = fopen($url, "r")) {
while ($tmp = fget($fp, 4096)) $output .= $tmp;
fclose($fp);
}
echo "The URL's content is: ".$output;
?>
The "4096" part just means it will pull from the file pointer ($fp) in 4096
byte blocks (or chunks), and the while will keep pulling the chunks until
there is nothing left to pull.
--
Dan Hardiker [dhardiker@staff.firstcreative.net]
ADAM Software & Systems Engineer
First Creative Ltd