<?php //curl下载远程图片到服务器 方法 function download($url, $path = ‘images/‘){ $ch = curl_init(); $names = mt_rand(100000,999999); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); $file = curl_exec($ch); curl_close($ch); $filename = pathinfo($url, PATHINFO_BASENAME); $lujing = $path . $names; if(!is_dir($lujing)){ mkdir(iconv("UTF-8", "GBK", $lujing),0777,true); } //$resource = fopen($path . $names.‘/‘.$filename, ‘a‘); $info = file_put_contents($path . $names.‘/‘.$filename,$file); if($info){ return $path . $names.‘/‘.$filename; } //fwrite($resource, $file); //fclose($resource); }
原文地址:https://www.cnblogs.com/shenchanglu/p/11864853.html
时间: 2024-11-07 12:07:36