Php remote image collection

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.