PHP CURL抓取远程图片到服务器指定目录存储 /* *CURL获取图片并存储到服务器本地指定目录 *@path 图片的URL地址(必须有jpg png jpeg gif等后缀) *@file_dir 图片存储在服务器的地址 */ function saveImage($path,$file_dir) { 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($file_dir.$image_name,’w’); fwrite($fp, $img); fclose($fp); } saveImage(‘http://e.topthink.com/Uploads/Picture/2016-06-12/575ccd9534272.png’,’./’); ?> (责任编辑:好模板) |