note 54878 deleted from function.readfile by philip
| From: | philip@php.net | Date: | Mon, 05 Mar 2007 06:28:16 +0000 |
| Subject: | note 54878 deleted from function.readfile by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-124083@lists.php.net to get a copy of this message | ||
Note Submitter: cenaculo at netcabo dot pt
----
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.