PHP function grabs remote images to local

WBOY
Release: 2016-07-25 08:51:39
Original
1658 people have browsed it
  1. //php ob function library to grab remote images

  2. function GetImage($url, $filename = "") {
  3. if ($url == "") {
  4. return false;
  5. }
  6. if ($filename == "") {
  7. $ext = strrchr ( $url, "." );
  8. if ($ext != ".gif" && $ext != ".jpg ") {
  9. return false;
  10. }
  11. $filename = time () . $ext;
  12. }

  13. //File saving path

  14. ob_start ();
  15. readfile ( $url );
  16. $img = ob_get_contents ();
  17. ob_end_clean ();
  18. $size = strlen ( $img );

  19. //File size

  20. $fp2 = @fopen ( $filename, "a" ) ;
  21. fwrite ( $fp2, $img );
  22. fclose ( $fp2 );
  23. return $filename;
  24. }

  25. GetImage ( "http://XXXXX" );

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