/**
* 通过curl下载
* @param string $url网上资源图片的url
* @return string
*/
function download($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);//超过3秒不处理
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //执行之后信息以文件流的形式返回
$file = curl_exec($ch);
curl_close($ch);
return $file;
}
/**
* 将读取的图片流写入指定文件
* @param string $path要存入目标图片,权限要为777
* @param string $url网上资源图片的url
* @return string
*/
function write($path,$url){
$file=@download($url);
if($file){
$path=file_put_contents($path,$url);
if($path){
return $path;
}
}
}
//调用
write("www/...","https://res.vmallres.com/pimages//product/6901443267491/428_428_1554811462815mp.png");