返回图片保存路径可选择根据需要保存到数据库 $url=str_replace('&','&',$url); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; SeaPort/1.2; Windows NT 5.1; SV1; InfoPath.2)"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0); $values = curl_exec($curl); curl_close($curl); $fileName = time().rand(5,10).'.jpg'; $savePath = "/uploads/category/".date('Ymd',time()).'/'; $path = ROOT_PATH.'public'.$savePath; if(!is_dir($path)){ mkdir($path,'0755',true); } $fp2 = fopen($path.$fileName,'wb'); fputs($fp2, $values); fclose($fp2); return $savePath.$fileName; } |
php通过网页图片地址将图片保存到本地
最新推荐文章于 2023-03-16 22:45:00 发布