The example in this article describes how PHP gets a remote picture and saves it locally. Share to everyone for your reference. The implementation methods are as follows:
<?php
function Grabimage ($url, $filename = "") {
if ($url = = ""): return false;
endif;
If the $url address is empty, simply exit if
($filename = = "") {
//If no new filename is specified
$ext = STRRCHR ($url, ".");
Get $url Picture Format
if ($ext!= ". gif" && $ext!= ". jpg"): return false;
endif;
If the picture is not formatted as. gif or. jpg, exit
$filename = Date ("Dmyhis") directly. $ext;
Name the new filename on the day of the month (
ob_start);//Open Output
ReadFile ($url);//Output picture file
$img = ob_get_contents ();// Get the browser output
Ob_end_clean ()//clear output and close
$size = strlen ($img);//Get picture size
$fp 2 = @fopen ($filename, "a");
Fwrite ($fp 2, $img);//write a picture file to the current directory and rename
fclose ($fp 2);
return $filename//returns a new filename
}
$img = Grabimage ("Yun_qi_img/6648d73db0edd1e89f3d62f7.gif", "");
if ($img): Echo ' <pre></pre> ';
If the return value is true, this shows that the picture that has been collected on the server
Else:echo "false";
endif;
Otherwise, the output acquisition fails
?>
I hope this article will help you with your PHP program design.