Home >Backend Development >PHP Tutorial >PHP download remote image to local development example sharing

PHP download remote image to local development example sharing

黄舟
黄舟Original
2017-08-17 09:41:492074browse

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(&#39;jpg&#39;, &#39;gif&#39;, &#39;png&#39;);

$img=download_image("$url","","$dirName",$fileType = array(&#39;jpg&#39;, &#39;gif&#39;, &#39;png&#39;),$type = 1);//下载远程图片并保存到本地

var_dump($img);//打印数据,
?>

The running result is as shown below:

PHP download remote image to local development example sharing

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!

PHP download remote image to local development example sharing

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn