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:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 The |
<?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 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 ("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?> the |
I hope this article will help you with your PHP programming.