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

PHP 抓取網頁圖片并且另存為的實現代碼

下面是源代碼,及其相關解釋
復制代碼 代碼如下:
<?php
//URL是遠程的完整圖片地址,不能為空, $filename 是另存為的圖片名字
//默認把圖片放在以此腳本相同的目錄里
function GrabImage($url, $filename=""){
//$url 為空則返回 false;
if($url == ""){return false;}
$ext = strrchr($url, ".");//得到圖片的擴展名
if($ext != ".gif" && $ext != ".jpg" && $ext != ".bmp"){echo "格式不支持!";return false;}
if($filename == ""){$filename = time()."$ext";}//以時間戳另起名
//開始捕捉
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. (輸出是在內部緩沖儲存)
//
readfile : 讀入一個文件并寫入到輸出緩沖
返回從文件中讀入的字節數。如果出錯返回 FALSE 并且除非是以 @readfile() 形式調用,否則會顯示錯誤信息。
//

ob_get_contents : Return the contents of the output buffer(返回輸出緩沖的內容)
This will return the contents of the output buffer without clearing it or FALSE, if output buffering isn't active. (如果輸出緩沖沒有活動(打開),則返回 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.(丟棄并且關掉) 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. (如果要用緩沖內容,則在清理輸出緩沖之前要先調用 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技術PHP 抓取網頁圖片并且另存為的實現代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 一本大道久久a久久综合 | 五月开心激情网 | 亚洲免费一区二区 | 在线视频一区二区三区在线播放 | 日韩在线视屏 | 精品国产免费观看一区 | 亚洲狠狠婷婷综合久久久久图片 | 色吧综合网 | 日韩中文字幕亚洲无线码 | 国产一级特黄aa级特黄裸毛片 | 伊人久久大香线蕉综合7 | 成年美女黄的视频网站 | 国产精品日韩欧美在线第3页 | 伊人久久大香线蕉综合高清 | 成人免费动作大片黄在线 | 女人笫一次一级毛片 | 国产视频精品免费 | 五月婷婷色 | 秋霞伊人网 | 国产午夜视频在线观看网站 | 五月天激情综合网 | 日本www色视频成人免费免费 | 夜夜综合| 四虎影视免费永久在线观看 | 久久网页 | 婷婷丁香综合网 | 国产成人一区二区三区影院免费 | 免费91最新地址永久入口 | 一二三区无线码2021 | 在线成人爽a毛片免费软件 在线成人小视频 | 久久免费精彩视频 | 色www亚洲 | 婷婷色视频 | 2020国产成人免费视频 | 色多多www视频在线观看免费 | 亚欧成人乱码一区二区 | 91久久精品 | 久久精品国产99久久无毒不卡 | 国产对白精品刺激一区二区 | 午夜看片未满十八勿进 | 国外成人免费视频 |