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

PHP downloads images based on URL

WBOY
Release: 2016-07-25 08:42:41
Original
1404 people have browsed it
  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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template