Home > php教程 > php手册 > body text

php保存任意网络图片到服务器的方法,

WBOY
Release: 2016-06-13 09:07:02
Original
815 people have browsed it

php保存任意网络图片到服务器的方法,

本文实例讲述了php保存任意网络图片到服务器的方法。分享给大家供大家参考。具体分析如下:

任意指定一个网络图片地址,通过这个函数下载到本地服务器

<&#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

希望本文所述对大家的php程序设计有所帮助。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!