You are here: Re: create file (image) based on header « PHP Programming Language « IT news, forums, messages
Re: create file (image) based on header

Posted by christiang on 03/13/06 00:19

If I use fopen($url) I'm able to copy the stream:

$buffer = fopen($url,"r");
if ($buffer)
{
$head = fread($buffer, 4096);
print("first: ".preg_match('[Content-Type: image/gif]', $head));
print("second: ".preg_match('#^HTTP/.*\s+[200|302]+\s#i', $head));
//print($head."<br>");
if(!preg_match('[Content-Type: image/gif]', $head) &&
preg_match('#^HTTP/.*\s+[200|302]+\s#i', $head)){
print("found image!<br>");
$foundThumb = true;
$content = $head;
while (!feof($buffer))
{
$content .= fread($buffer, 8192);
}
$ourFileHandle = fopen($this->thumbs_folder."/".$name, 'w');
fputs($ourFileHandle,$content);
fclose($ourFileHandle);
}
fclose($buffer);
}

but then my regex don't work anymore. I tried to create put together
the stream in my previous code:

if(!preg_match('[Content-Type: image/gif]', $head) &&
preg_match('#^HTTP/.*\s+[200|302]+\s#i', $head)){
print("found image!<br>");
$foundThumb = true;
$content = $head;
while (!feof($fid))
{
$content .= fread($fid, 8192);
}
$ourFileHandle = fopen($this->thumbs_folder."/".$name, 'w');
fputs($ourFileHandle,$fid);
fclose($ourFileHandle);
}

but the files are corrupted (ridiculous small size). Any clue?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация