The following code how to download to the specified directory
/**
* Crawl Remote Pictures
*
* @param string $url remote picture path
* @param string $filename Local store file name
*/
function Grabimage ($url, $filename = ") {
if ($url = = ") {
return false; Returns False if the $url is empty;
}
$ext _name = STRRCHR ($url, '. '); Get the name extension of a picture
if ($ext _name! = '. gif ' && $ext _name! = '. jpg ' && $ext _name! = '. bmp ' && $ext _name! = '. png ') {
return false; Format is not in allowed range
}
if ($filename = = ") {
$filename = Time (). $ext _name; Named by Time stamp
}
Start capturing
Ob_start ();
ReadFile ($url);
$img _data = ob_get_contents ();
Ob_end_clean ();
$size = strlen ($img _data);
$local _file = fopen ($filename, ' a ');
Fwrite ($local _file, $img _data);
Fclose ($local _file);
return $filename;
}
The above code can download remote pictures to local, but how to download to the specified directory and get the downloaded file name and directory
Trouble to know the master directly to the code, thank you
Share to: more
------Solution--------------------
This function is not OK, the second parameter you can not be arbitrarily specified? For example, the second parameter passed e:/test/1_u013032668.jpg in, and naturally downloaded to the E:/test directory.