Copy code The code is as follows:
function grabImage($url, $filename = '') {
if($url = = '') {
return false; //If $url is empty, return false;
}
$ext_name = strrchr($url, '.'); //Get the extension of the image
if($ext_name != '.gif' && $ext_name != '.jpg' && $ext_name != '.bmp' && $ext_name != '.png') {
return false; //Format Not within the allowed range
}
if($filename == '') {
$filename = time().$ext_name; //Rename with timestamp
}
// Start capturing
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.htmlTechArticleCopy the code as follows: function grabImage($url, $filename = '') { if($url == '') { return false; //If $url is empty, return false; } $ext_name = strrchr($url, '.'); //Get the image...