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!