Posted on

使用php抓取網路上的圖片

首先要先至網站上下載snoopy類別
可用以模擬表單送交或是抓取網路頁面
http://snoopy.sourceforge.net/
然後使用下面的範例程式就可以順利下載圖檔了

include("snoopy.class.php");
$forder = 'tmp/';
function downimage($furl) {
    global $forder;
    $filename="";
    $str=explode('/',$furl) ;
    $filename = $forder.$str[count($str)-1] ;

    $snoopyx = new Snoopy ;
    $snoopyx->fetch($furl) ;

    if($snoopyx->results !="")
    {
        $handle = fopen($filename, 'w') ;
        fwrite($handle, $snoopyx->results) ; //把抓取得內容寫到 臨時文件中
        fclose($handle) ;
    }
    return $filename ;
}
echo downimage('http://tw-wowbox.meetgee.com/images/icons/inv_belt_mail_raidshaman_i_01.jpg');