複製程式碼 程式碼如下:
function grabImage($url, $filename = '') {
if($url = = '') {
return false; //如果$url 為空則回傳false;
}
$ext_name = strrchr($url, '.'); //取得圖片的副檔名
if($ext_name != '.gif' && $ext_name != '.jpg' && $ext_name != '.bmp' && $ext_name != '.png') {
return false; //格式不在允許的範圍
}
if($filename == '') {
$filename = time().$ext_name; //以時間戳另起名
}
//開始捕獲
ob_start();
readfile($url);
$img_data = ob_get_contents();
ob_end_clean();
$size = strlen($img_data); $local_file = fopen($filename , 'a');
fwrite($local_file, $img_data);
fclose($local_file);
return $filename;
}
http://www.bkjia.com/PHPjc/313576.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313576.htmlTechArticle複製程式碼如下: function grabImage($url, $filename = '') { if($url == '') { return false; //如果$url 為空則回傳false; } $ext_name = strrchr($url, '.'); //取得圖...