url下载文件到本地

$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

 

posted on 2018-11-09 17:46  薇薇123456  阅读(151)  评论(0编辑  收藏  举报

导航