note 54878 added to function.readfile

From: Date: Mon, 18 Jul 2005 19:09:35 +0000
Subject: note 54878 added to function.readfile
Groups: php.notes 
Request: Send a blank email to php-notes+get-92125@lists.php.net to get a copy of this message
This is a good function to overcome the Animated GIF problem in PHP, sending a GIF as a normal file, just putting a header before, just to tell the browser that you are sending a GIF. This was the only way i found to send an animated GIF that really animates in the browser. The code i reproduce here is not mine, but posted before by chrisputnam at gmail dot com, and it works just fine, i just putted the header before: <?php function readfile_chunked($filename,$retbytes=true) { $chunksize = 1*(1024*1024); // how many bytes per chunk $buffer = ''; $cnt =0; // $handle = fopen($filename, 'rb'); $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, $chunksize); echo $buffer; flush(); if ($retbytes) { $cnt += strlen($buffer); } } $status = fclose($handle); if ($retbytes && $status) { return $cnt; // return num. bytes delivered like readfile() does. } return $status; } $vfile = "filename.gif"; header("Content-type: image/gif"); readfile_chunked($vfile,false); ?> The code i had before was like this: <?php $vfile = "filename.gif"; $im = imagecreatefromgif($vfile); header("Content-type: image/gif"); imagegif($im); ?> But it only shows the first frame of the Animated GIF. ---- Manual Page -- http://www.php.net/manual/en/function.readfile.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54878 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54878&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54878&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54878&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54878&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54878&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54878&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54878&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92125) next »