Home > Backend Development > PHP Tutorial > How to save any network image to the server in php_PHP tutorial

How to save any network image to the server in php_PHP tutorial

WBOY
Release: 2016-07-13 09:57:18
Original
844 people have browsed it

How to save any network pictures to the server in php,

This article describes the method of saving any network pictures to the server in php. Share it with everyone for your reference. The specific analysis is as follows:

Specify any network image address and download it to the local server through this function

<&#63;php
function saveImage($path) {
 if(!preg_match('/\/([^\/]+\.[a-z]{3,4})$/i',$path,$matches))
 die('Use image please');
 $image_name = strToLower($matches[1]);
 $ch = curl_init ($path);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
 $img = curl_exec ($ch);
 curl_close ($ch);
 $fp = fopen($image_name,'w');
 fwrite($fp, $img);
 fclose($fp);
}
saveImage('http://www.bkjia.com/images/logo.jpg');
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/984002.htmlTechArticleHow to save any network pictures to the server in php. This article describes the method of saving any network pictures to the server in php. Share it with everyone for your reference. The specific analysis is as follows: Ren...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template