Get remote pictures to local (audio and video are also available)

WBOY
Release: 2016-07-25 08:47:31
Original
1049 people have browsed it
Remote pictures are obtained locally (audio and video are also acceptable) and cannot be specially encrypted.
  1. function GrabImage($url,$filename="")
  2. {
  3. if($url==""):return false;endif;
  4. if($filename=="") {
  5. $ext=strrchr ($url,".");
  6. if($ext!=".gif" && $ext!=".jpg"):return false;endif;
  7. $filename_r=time().rand(10,9000) .$ext;
  8. $filename='get_images/'.$filename_r;
  9. }
  10. ob_start();
  11. readfile($url);
  12. $img = ob_get_contents();
  13. ob_end_clean();
  14. $size = strlen($ img);
  15. $fp2=@fopen($filename, "a");
  16. fwrite($fp2,$img);
  17. fclose($fp2);
  18. return $filename_r;
  19. }
  20. $img=GrabImage(" http://cdn.iciba.com/news/word/big_2014-07-16b.jpg");
  21. if($img):echo '
    <img src="get_images/'.$img. '">
    ';
  22. else:echo "false";
  23. endif;
Copy code


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!