Home > Backend Development > PHP Tutorial > Sharing a PHP remote image grabbing function_PHP tutorial

Sharing a PHP remote image grabbing function_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 16:13:07
Original
906 people have browsed it

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;
}

www.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...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why does it still jump after returning false?
From 1970-01-01 08:00:00
0
0
0
Optimize table indexes in MySQL
From 1970-01-01 08:00:00
0
0
0
Why can't I install it?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template