|
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]
|