采集图片的几种方法,通常都是通过curl进行。

方法一:

/** 获取远程图片**/ 
function getImage($uri,$from){ 
    ob_start(); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $uri); 
    if($from){ 
        curl_setopt($ch,CURLOPT_REFERER, $from); 
    }                
    curl_exec($ch); 
    $img = ob_get_contents(); 
    ob_end_clean(); 
    curl_close($ch); 
    return $img; 
} 
//$uri = "http://feelgrafix.com/data_images/out/10/839665-laser-wallpaper.jpg"; 
//$from = "http://feelgrafix.com/"; 
// 
//$fs = fopen("c:\\abc.jpg","w+"); 
//fwrite($fs,getImage($uri,$from)); 
//fclose($fs); 
//以上就是采集图片和采集防盗链图片的基本方法咯//

方法二:

function save_from_url($inPath,$outPath) 
{ //Download images from remote server 
    $in=    fopen($inPath, "rb"); 
    $out=   fopen($outPath, "w+"); 
    while ($chunk = fread($in,18192)) 
    { 
        fwrite($out, $chunk, 18192); 
    } 
    fclose($in); 
    fclose($out); 
}

之前已有文章详细介绍过3种php采集方法,具体阅上一篇文章