Home >Backend Development >PHP Tutorial >PHP downloads images based on URL

PHP downloads images based on URL

WBOY
WBOYOriginal
2016-07-25 08:42:411398browse
  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. }
Copy code

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

Download image, PHP, URL


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn