Today in the collation of information to find a previously found function, through this function we can achieve the above function.
Main functions:
Copy Code code as follows:
function Grabimage ($url, $filename = "") {
if ($url = = "") return false;
if ($filename = = "") {
$ext =STRRCHR ($url, ".");
if ($ext!= ". gif" && $ext!= ". jpg" && $ext!= ". png") return false;
$filename =date ("Ymdhis"). $ext;
}
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;
}
Get the code for a picture:
Copy Code code as follows:
$img =grabimage ("Yun_qi_img/baidu_logo.gif", "logo.gif");
if ($img) {
Echo ' ';
}else{
echo "false";
}
This is an example of preserving Google's logo, which is saved under the same sibling directory.
Get a series of regular pictures (for example: 100 pictures named after the number 1-100):
Copy Code code as follows:
For ($i =1 $i <=100; $i + +) {
$img =grabimage ("yun_qi_img/$i. gif", "images/$i. gif");
}
The www.yourimagesite.com above is the image URL, you need to modify, after the program execution, all the pictures will be saved under the images directory.