首页 >后端开发 >php教程 >PHP根据 URL 下载图片

PHP根据 URL 下载图片

WBOY
WBOY原创
2016-07-25 08:42:411398浏览
  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


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn