Php retrieves remote images and saves them to a local device.

Source: Internet
Author: User
A blog can automatically switch the background image, but the background image exists elsewhere. so I want to save it to the website server and write a code segment.

A blog can automatically switch the background image, but the background image exists elsewhere. so I want to save it to the website server and write a code segment.

I hope you will give more comments or suggestions.

 

The path of the image is saved in the txt text file and has been wrapped in a line break. Therefore, it is easy to convert the image path into an array for processing.
Set_time_limit (0); set the execution time. the number in the brackets is the execution time. if it is zero, it is permanently executed until the end of the program. if it is a number greater than zero, no matter whether the program is completed or not, the program ends at the specified number of seconds.

The pathinfo () function returns the file path information in an array. For details, see the previous article introduction: N methods for getting File extensions in php.

The uniqid () function generates a unique ID based on the current time in microseconds.

After obtaining the suffix of the image, file_get_contents () gets the image content. file_put_contents () writes down the image content so that the image is saved. isn't it easy.

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.