经测试代码如下:
<?PHP
/**
* 远程图片保存
*
* @param
* @arrange (512.笔记) jb51.cc
**/
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://*/513_jsFromNull/javascript-from-null.jpg');
/*** 代码来自编程之家 jb51.cc(jb51.cc) ***/
任意指定一个网络图片地址,通过这个函数下载到本地服务器 原文链接:https://www.f2er.com/php/528826.html