PHP Download remote file Store to local development sample introduction

Source: Internet
Author: User
In our daily development work, sometimes we need to develop the collector to publish the interface this will be used to remote attachment function, this is the need to use PHP remote download files stored locally to the function, if the server supports the Curl function, the program will prefer curl, Because the test results show that Curl's response time and resource occupancy rate are much smaller than file_get_contents.

First, we still need to download the PHP download remote file to local storage function class Library: http://www.php.cn/xiazai/leiku/805

After the download, find the PHP class files we need, unzip to our local directory, create a new PHP file!

Once this is done, we will invoke this class in the new PHP file, and instantiate the class:

<?phpinclude_once "codexiazai.php"; Introduce class file $img=grabimage ("//Remote File connection if ($img) echo ' <pre></pre> ';          The output shows else echo "false";? >

The results of the operation are as follows:

When we run the page after the display is a picture, when we open the local directory, the image already exists in our local, such as:

Description

Here we use a download image as an example, when we refresh each page locally will store a picture and the same as before, there is a function in the class, when we call the function, refresh the page when the page display is only the name, not the picture, here is not to show you, the fundamental instance is almost the same, The little friends can try it on their own!

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.