Home  >  Article  >  Backend Development  >  Get remote pictures to local (audio and video are also available)

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

WBOY
WBOYOriginal
2016-07-25 08:47:311100browse
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


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