Ob_start: Turn on output buffering
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