note 26824 modified in function.fread by danbrown

From: Date: Fri, 06 Jan 2012 21:13:23 +0000
Subject: note 26824 modified in function.fread by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185443@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.example.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. <?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. http://php.net/manual/en/function.fread.php

« previous php.notes (#185443) next »