The following code is a code example for PHP to capture images:
- < ?php
- // Variable description:
- // $url is the complete URL address of the remote image and cannot be empty.
- // $filename is an optional variable: if empty,
the local file name will be automatically generated based on time and date. - function GrabImage($url,$filename="") {
- if ($url==""):return false;endif;
- if($filename=="") {
- $ext=strrchr ($url,".");
- if($ext!=".gif" && $ext!=".jpg"):
return false;endif; - $filename=date("dMYHis").$ext;
- }
- ob_start();
- readfile($url);
- $img = ob_get_contents();
- ob_end_clean();
- $size = strlen($img);
- $fp2=@fopen($filename, "a");
- fwrite($fp2,$img);
- fclose($fp2); 🎜>}
- $
- img=
- GrabImage("Image path ",""); if($img):echo '<pre
- > <img
src="'.$img.' ">pre>'; else:echo "false"; endif; >
-
I hope you can use the method of capturing images with PHP introduced in this article and become proficient in using this method.
-
- 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...
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