一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

PHP 抓取網(wǎng)頁圖片并且另存為的實(shí)現(xiàn)代碼

下面是源代碼,及其相關(guān)解釋
復(fù)制代碼 代碼如下:
<?php
//URL是遠(yuǎn)程的完整圖片地址,不能為空, $filename 是另存為的圖片名字
//默認(rèn)把圖片放在以此腳本相同的目錄里
function GrabImage($url, $filename=""){
//$url 為空則返回 false;
if($url == ""){return false;}
$ext = strrchr($url, ".");//得到圖片的擴(kuò)展名
if($ext != ".gif" && $ext != ".jpg" && $ext != ".bmp"){echo "格式不支持!";return false;}
if($filename == ""){$filename = time()."$ext";}//以時(shí)間戳另起名
//開始捕捉
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;
}
//測試
GrabImage("http://www.jb51.NET/images/logo.gif", "as.gif");
?>

ob_start : 打開輸出緩沖
This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. (輸出是在內(nèi)部緩沖儲(chǔ)存)
//
readfile : 讀入一個(gè)文件并寫入到輸出緩沖
返回從文件中讀入的字節(jié)數(shù)。如果出錯(cuò)返回 FALSE 并且除非是以 @readfile() 形式調(diào)用,否則會(huì)顯示錯(cuò)誤信息。
//

ob_get_contents : Return the contents of the output buffer(返回輸出緩沖的內(nèi)容)
This will return the contents of the output buffer without clearing it or FALSE, if output buffering isn't active. (如果輸出緩沖沒有活動(dòng)(打開),則返回 FALSE)
//
ob_end_clean() : Clean (erase) the output buffer and turn off output buffering(清除輸出緩沖)
This function discards(丟棄) the contents of the topmost output buffer and turns off this output buffering.(丟棄并且關(guān)掉) If you want to further process the buffer's contents you have to call ob_get_contents() before ob_end_clean() as the buffer contents are discarded when ob_end_clean() is called. (如果要用緩沖內(nèi)容,則在清理輸出緩沖之前要先調(diào)用 ob_get_contents())The function returns TRUE when it successfully discarded one buffer and FALSE otherwise. Reasons for failure are first that you called the function without an active buffer or that for some reason a buffer could not be deleted (possible for special buffer).

php技術(shù)PHP 抓取網(wǎng)頁圖片并且另存為的實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 在线观看国产情趣免费视频 | 六月婷婷精品视频在线观看 | 7799国产精品久久久久99 | 9久久免费国产精品特黄 | 国产成人精品区在线观看 | 国内精品久久久久久久亚洲 | 日韩专区中文字幕 | 国内精品视频区在线2021 | 亚洲国产欧美91 | 91色网站| 五月婷婷六月爱 | 四虎永久免费最新在线 | 男人扒开女人腿使劲桶动态图 | 欧美在线色 | 国内自拍第1页 | xxxxxbbbbb欧美性极品 | 91免费视频网 | 中文字幕一区二区三区视频在线 | 91视频插插插 | 久久国产香蕉一区精品 | 国产视频一区二区在线观看 | 韩国一区二区三区视频 | 丝袜综合网 | 中文字幕一区二区三区有限公司 | 开心激情综合网 | 九九精品在线视频 | 亚洲不卡一区二区三区 | www.狠狠| 怡红院一区二区在线观看 | 91成人午夜精品福利院在线观看 | 91高清视频 | 一区二区三区四区在线播放 | 亚洲综合色播 | 2021久久精品国产99国产 | 国产成人lu在线视频 | 欧美91精品 | 天天综合天天做天天综合 | 亚洲国产欧美国产第一区二区三区 | 久久91精品国产91久久跳舞 | 成人精品在线视频 | 国产精选在线 |