Explanation of PHP remote image obtaining tips _ PHP Tutorial

Source: Internet
Author: User
Explain in detail how PHP can get remote images. Code example for PHP to obtain remote images: functiongethttpimage ($ url) {set_time_limit (0); if (! Empty ($ url) {$ imgUrldate (Y-m, time ()... uniqid (). strrchr ($ url,.); $ imgPathAPP _

PHP code example for obtaining remote images:

  1. Function gethttpimage ($ url ){
  2. Set_time_limit (0 );
  3. If (! Empty ($ url )){
  4. $ ImgUrl = date ('Y-M', time ()).'/'.
    Uniqid (). strrchr ($ url ,".");
  5. $ ImgPath = APP_PATH. '/Public
    /Uploads /';
  6. $ Filename = $ imgPath. $ imgUrl;
  7. If (! Is_dir ($ imgPath) @ mkdir
    ($ ImgPath, 0777 );
  8. $ Get_file = @ file_get _
    Contents ($ url );
  9. If ($ get_file ){
  10. $ Fp = @ fopen ($ filename, "w ");
  11. @ Fwrite ($ fp, $ get_file );
  12. @ Fclose ($ fp );
  13. }
  14. Return $ imgUrl;
  15. } Else {
  16. Return false;
  17. }
  18. }

The above code describes how PHP can obtain remote images.


Extends functiongethttpimage ($ url) {set_time_limit (0); if (! Empty ($ url) {$ imgUrl = date ('Y-M', time ()). '/'. uniqid (). strrchr ($ url ,.); $ imgPath = APP _...

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.