当前位置:Gxlcms > PHP教程 > PHP根据URL下载图片

PHP根据URL下载图片

时间:2021-07-01 10:21:17 帮助过:22人阅读

  1. function imagefromURL($image,$rename)
  2. {
  3. $ch = curl_init($image);
  4. curl_setopt($ch, CURLOPT_HEADER, 0);
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  6. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  7. $rawdata=curl_exec ($ch);
  8. curl_close ($ch);
  9. $fp = fopen("$rename",'w');
  10. fwrite($fp, $rawdata);
  11. fclose($fp);
  12. }

用法:
  1. $url = "http://img.it-home.org/data/attachment/forum/2016pic2/logo.png";
  2. $rename = "koonk.png";
  3. imagefromURL($url,$rename);
  4. ?>

下载图片, PHP, URL

人气教程排行