Home > Backend Development > PHP Tutorial > Specific implementation method of capturing images with PHP_PHP tutorial

Specific implementation method of capturing images with PHP_PHP tutorial

WBOY
Release: 2016-07-15 13:31:57
Original
1156 people have browsed it

The following code is a code example for PHP to capture images:

  1. < ?php
  2. // Variable description:
  3. // $url is the complete URL address of the remote image and cannot be empty.
  4. // $filename is an optional variable: if empty,
    the local file name will be automatically generated based on time and date.
  5. function GrabImage($url,$filename="") {
  6. if ($url==""):return false;endif;
  7. if($filename=="") {
  8. $ext=strrchr ($url,".");
  9. if($ext!=".gif" && $ext!=".jpg"):
    return false;endif;
  10. $filename=date("dMYHis").$ext;
  11. }
  12. ob_start();
  13. readfile($url);
  14. $img = ob_get_contents();
  15. ob_end_clean();
  16. $size = strlen($img);
  17. $fp2=@fopen($filename, "a");
  18. fwrite($fp2,$img);
  19. fclose($fp2); 🎜>
  20. $
  21. img=
  22. GrabImage("Image path ",""); if($img):echo '<pre
  23. > <img
    src="'.$img.' ">pre>'; else:echo "false"; endif; >
  24. I hope you can use the method of capturing images with PHP introduced in this article and become proficient in using this method.
  25. http://www.bkjia.com/PHPjc/446171.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/446171.html

TechArticle

The following code is a code example for PHP to capture images: ?php //Variable description: //$url is remote The complete URL address of the image, which cannot be empty. //$filename is an optional variable: if it is empty, the local file...

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