时间:2021-07-01 10:21:17 帮助过:25人阅读
任意指定一个网络图片地址,通过这个函数下载到本地服务器
<?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.gxlcms.com/images/logo.jpg'); ?>
希望本文所述对大家的php程序设计有所帮助。