note 26824 modified in function.fread by aidan
| From: | aidan@php.net | Date: | Thu, 01 Jul 2004 08:45:34 +0000 |
| Subject: | note 26824 modified in function.fread by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72241@lists.php.net to get a copy of this message | ||
I spent a while trying to get this to work so I thought I'd share.
Here's how to read a remote binary file using fread.
<?php
$fp = fopen("http://www.site.com/img.jpg", "rb");
if($fp){
while(!feof($fp))
{
$img = $img . fread($fp, 1024);
}
}
?>
This will read the contents of the file into the var $img 1024 bytes at a time. I used that number
because it seemed safe, but you can increment it all you want I guess.
I don't know if everyone but me gets this, but I thought I'd share since I didn't see
anything like it out there.
--was--
I spent a while trying to get this to work so I thought I'd share.
Here's how to read a remote binary file using fread.
$fp = fopen("http://www.site.com/img.jpg", "rb");
if($fp){
while(!feof($fp))
{
$img = $img . fread($fp, 1024);
}
}
This will read the contents of the file into the var $img 1024 bytes at a time. I used that number
because it seemed safe, but you can increment it all you want I guess.
I don't know if everyone but me gets this, but I thought I'd share since I didn't see
anything like it out there.
http://php.net/manual/en/function.fread.php