$url = 'http://czd.111.net/extra/car2.jpg'; function download($url, $path = './huahua.jpg') { $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); } download($url);die;
注意:图片地址不能为https