ReadFile: Reads a file and writes to the output buffer Returns the number of bytes read from a file. If the error returns false and an error message is displayed unless invoked in the form of @readfile ().
Ob_end_clean (): Clean (erase) The output buffer and turn off output buffering (clear out buffer)
<?php Tutorial URL is a remote full picture address, can not be empty, $filename is saved as a picture name Default to put the picture in the same directory as the script function Grabimage ($url, $filename = "") { returns false $url null; if ($url = = "") {return false;} $ext = STRRCHR ($url, "."); /Get the image extension if ($ext!= ". gif" && $ext!= ". jpg" && $ext!= ". bmp") {echo format is not supported! "; return false;} if ($filename = = "") {$filename = time (). $ext ";} Another name with a timestamp Start capturing Ob_start (); ReadFile ($url); $img = Ob_get_contents (); Ob_end_clean (); $size = strlen ($img); $FP 2 = fopen ($filename, "a"); Fwrite ($fp 2, $img); Fclose ($fp 2); return $filename; } Test Grabimage ("Http://www.jzread.com/skin/default/imga/logo.gif", "as.gif"); ?>
PHP captures remote Web page images and saves them to local
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.