Home > Article > Backend Development > PHP download remote image to local development example sharing
In our previous articlephp download remote file storage to local development example introduction, we introduced how to implement php download remote file to local storage, I believe many friends can easily Got it, so how do we implement PHP to download remote images? Today I will introduce to you how to use PHP to download remote images and save them locally!
First we still need to download the PHP we need to download remote images to the local class library: http://www.php.cn/xiazai/leiku/647
After the download is complete, find the php class file we need, 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 "yuancxiazai.php";//引入类文件 //定义数值 $url = "http://imgsrc.baidu.com/imgad/pic/item/267f9e2f07082838b5168c32b299a9014c08f1f9.jpg"; $dirName = "D:/phpStudy/WWW/code"; $fileType = array('jpg', 'gif', 'png'); $img=download_image("$url","","$dirName",$fileType = array('jpg', 'gif', 'png'),$type = 1);//下载远程图片并保存到本地 var_dump($img);//打印数据, ?>
The running result is as shown below:
Note:
#1. In the above example, I agreed to the name of the downloaded image and the path to the image!
2. When we do not refresh the page, the picture will be saved again and the previous picture will not be overwritten.
3 .We can know the location of the image based on the image path above!
The above is the detailed content of PHP download remote image to local development example sharing. For more information, please follow other related articles on the PHP Chinese website!