note 26824 modified in function.fread by vincent

From: Date: Sat, 16 Aug 2003 13:52:13 +0000
Subject: note 26824 modified in function.fread by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54351@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. $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"); 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://www.php.net/manual/en/function.fread.php

« previous php.notes (#54351) next »