In our daily development work, sometimes we need to develop the collector publishing interface, which requires the use of the remote attachment function. For this, we need to use php to remotely download files and store them locally. If the server If the CURL function is supported, the program will give priority to CURL, because the test results show that CURL's response time and resource usage are much smaller than file_get_contents;
First we still have to download the php we need Download remote files to the locally stored function library: http://www.php.cn/xiazai/leiku/805
Find what we need after the download is complete php class file, unzip it to our local directory, and create a new php file!
After completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "codexiazai.php"; //引入类文件 $img=GrabImage(" //远程文件连接 if($img) echo '<pre class="brush:php;toolbar:false"><img src="'.$img.'" alt="PHP downloads remote files and stores them in local development example introduction" >
The running result is as shown below:
When we run it, the page displays pictures. When we open the local directory, the pictures already exist in our local directory, as shown below:
##Instructions:
Here we use the downloaded image as an example. Every time we refresh the page, we will store the same image here as before. There is also a function in the class. When we call this function and refresh the page, the page displays only the name, not the picture. I will not demonstrate it here. The basic examples are almost the same. You can try it yourself!
The above is the detailed content of PHP downloads remote files and stores them in local development example introduction. For more information, please follow other related articles on the PHP Chinese website!