将远程图片读取到本地,并保存

//将远程图片读取到本地,并保存
function grap_Image($url) 
{ 
if($url=="")    return false;
$filename = md5($url) . '.jpg';
if(file_exists($filename))
{
return $filename;
}

ob_start(); 
readfile($url); 
$img = ob_get_contents(); 
ob_end_clean(); 
$size = strlen($img); 
$fp2=@fopen($filename, "a"); 
fwrite($fp2,$img); 
fclose($fp2); 
return $filename; 
}
posted @ 2012-11-30 10:22  小伍BLOG  阅读(487)  评论(0编辑  收藏  举报