Share a PHP remote image capturing function. The copy code is as follows: functiongrabImage ($ url, $ filename) {if ($ url) {returnfalse; if $ url is empty, false is returned ;} $ ext_namestrrchr ($ url ,.); retrieve graph
The code is as follows:
Function grabImage ($ url, $ filename = ''){
If ($ url = ''){
Return false; // if $ url is null, false is returned;
}
$ Ext_name = strrchr ($ url, '.'); // Obtain the image extension.
If ($ ext_name! = '.Gif '& $ ext_name! = '.Jpg '& $ ext_name! = '.Bmp '& $ ext_name! = '.Png '){
Return false; // The format is not in the permitted range.
}
If ($ filename = ''){
$ Filename = time (). $ ext_name; // name it with a timestamp
}
// Start capture
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;
}
The http://www.bkjia.com/PHPjc/313576.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/313576.htmlTechArticle code is as follows: function grabImage ($ url, $ filename = '') {if ($ url ='') {return false; // if $ url is null, false is returned.} $ ext_name = strrchr ($ url ,'. '); // Obtain the graph...