note 13114 deleted from function.fgets by sniper

From: Date: Sat, 08 Feb 2003 20:08:55 +0000
Subject: note 13114 deleted from function.fgets by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-43656@lists.php.net to get a copy of this message
I had important problems while trying to get an images size (the images were about 100 and 800 bytes) or just to get an image with fgets. I don't know why but it took only "GIF89a" and impossible to get something after this. However I use feof and fgets($fp, 4096) as in the example ! Test : <? $fp = fopen("http://www.php.net/gifs/php_logo.gif","r"); while(!feof($fp)) {$data .= fgets($fp, 4096);} fclose($fp); echo strlen($data); ?> It will return 1444. So if you have the same problem, this script will open a file (remote file or not) and if you want, you can get the REAL size. <? $url = "http://www.php.net/gifs/php_logo.gif"; // Or something else... ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); // Now $img is the file data. You DON'T have to use fopen, fgets, feof and fclose ! // And if you want to get the file size : $size = strlen($img); unset($img); ?> It returns 3872 ! And the real size of the PHP logo is 3872 so fgets seems to have some serious problems ;) [I tried this script under Widows98 with EasyPHP 1.3 (localhost)]

« previous php.notes (#43656) next »