PHP image collection function example
PHP image collection function example
If ($ url = '') {return false;} $ ext = strrchr ($ url ,'.');
If ($ ext! = '.Gif '& $ ext! = '.Jpg ') {return false ;}
// Determine whether the road Sutra exists! Is_dir ($ filepath )? Mkdir ($ filepath): null;
// Obtain the random image name with the suffix $ filetime = time (); $ filename = date ("YmdHis", $ filetime ). rand (100,999 ). '. '. substr ($ url,-3, 3 );
// Read the image $ img = fetch_urlpage_contents ($ url); // specify the opened file $ fp = @ fopen ($ filepath. '/'. $ filename, 'A'); // write the image to the specified text fwrite ($ fp, $ img); fclose ($ fp); return '/'. $ filepath. '/'. $ filename;} function fetch_urlpage_contents ($ url) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_TIMEOUT, 1000); $ file_contents = curl_exec ($ ch); curl_close ($ ch); r Eturn $ file_contents;} echo getimg (") // Image address // save path // return the saved path?>
The above is an example of the PHP image collection function. For more information, see The PHP Chinese website (www.php1.cn )!