PHP curl下载图片的方法
<?php
$images = [
'http://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKPkia3rxjuBoSQ1sUSmqYXDazibuIp8p2CCialBPjeYvcNJgky9P7hmlnDKgzX91utEQPu7VtsDqAIg/0',
];
function download($url, $path = 'dowloadceshi/2015-09-22_00-17-06j.png')
{
$ch = curl_init();
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);$resource = fopen($path, 'a');
fwrite($resource, $file);
fclose($resource);
}foreach ( $images as $url ) {
download($url);
}
?>
ps:如果采用file_get_contents方法发生图片下载过慢
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19119.html