Php remote image collection
Description of variables: $ url is the complete url address of the remote image. it cannot be blank. $ filename is an optional variable. if it is empty, the local file name is based on the time and date. automatically generated. the code is as follows: function grabimage ($ url, $ filename = "") {if ($ url = ""): return false; endif; if ($ filename = "") {$ ext = strrchr ($ url ,". "); if ($ ext! = ". Gif" & $ ext! = ". Jpg "): return false; endif; $ filename = date (" dmyhis "). $ ext;} ob_start (); readfile ($ url); $ img = ob_get_contents (); ob_end_clean (); // open source code phpfensi.com $ size = strlen ($ img ); $ fp2 = @ fopen ($ filename, "a"); fwrite ($ fp2, $ img); fclose ($ fp2); return $ filename ;} if fopen can be changed to the following: $ ch = curl_init (); curl_setopt ($ ch, curlopt_url, $ url); // This is the target address curl_setopt ($ ch, curlopt_header, 0); curl_setopt ($ ch, curlopt_returntransfer, 1); curl_setopt ($ ch, curlopt_referer, $ referer); // $ data = curl_exec ($ ch) is forged here ); curl_close ($ ch); echo $ data;