Re: saving a jpeg via HTTP
| From: | Daniel Tryba | Date: | Sat, 15 Jun 2002 16:02:58 +0000 |
| Subject: | Re: saving a jpeg via HTTP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-102349@lists.php.net to get a copy of this message | ||
On Sat, Jun 15, 2002 at 11:15:42AM -0400, Jeff Bearer wrote:
> I'm trying to read it with fsockopen and writing it with fopen to the
> file but the file is no good when it's saved, I saw that it saved the
> http headers in there so I cut those out but still, the image wan't
> viewable.
Are you using the binary safe fread/fwrite()? Didn't forget to fclose()
the output file?
This works for me:
<?php
if($fi=fsockopen("host",80))
{
fputs($fi,"GET /image.gif HTTP/1.0\r\n\r\n");
while(!preg_match("/^\r?\n$/",fgets($fi,1024))); //skip headers
while(!feof($fi))
{
if($fo=fopen("/tmp/tmp.gif","w"))
{
while(!feof($fi))
{
fwrite($fo,fread($fi,65535));
}
fclose($fo);
}
}
fclose($fi);
}
?>
--
Daniel Tryba