PHP bulk Download pictures, online Find the code, not good to make
function Project_statistics () {
echo "11111";
$url = "Http://www.xxx.com:81/upload/image";
$content =file_get_contents ($url);
$reg = "//";
Preg_match_all ($reg, $content, $matches);
$path = '. /download/img ';
if (!file_exists ($path)) {
mkdir ($path, 0777);
}
function Downimage ($url, $filename = "") {
if ($url = = "") return false;
if ($filename = = "") {
$ext =STRRCHR ($url, ".");
if ($ext! = ". gif" && $ext! = ". jpg" && $ext! = ". png" && $ext! = "JPEG") return false;
$filename =date ("Ymdhis"). $ext;
}
Ob_start ();
Make file, output from URL goes to buffer
ReadFile ($url);
File_get_contents ($url); This method is not possible!!! Only with ReadFile.
$img = Ob_get_contents ();
Ob_end_clean ();
[Email protected] ($filename, "a");//append
Fwrite ($fp, $img);
Fclose ($FP);
return $filename;
}
for ($i = 0; $i < count ($matches [1]); $i + +) {
/*explode
$url _arr[$i] = explode ('/', $matches [1][$i]);
$last = count ($url _arr[$i])-1;
*/
Strrchr
$filename = STRRCHR ($matches [1][$i], '/');
Downimage ($matches [1][$i], $path. $filename);
Downimage ($matches [1][$i], $path. ' /'. $url _arr[$i] [$last]);
}
}
Ask for advice, thank you. Just want to upload to the server pictures, all download Local. This has to be changed.
------to solve the idea----------------------
The code you give is the collection of all the image tags on the target page and downloads it.
If you want to download the image uploaded to the server, you can try to use the Downimage function in the above code to pass the URL of the server slice to the download.
------to solve the idea----------------------
Is there a picture URL?
Loop through all the URLs, then use file_get_contents to download it.
For example:
$url = "Http://www.abc.com/1.jpg";
$c = file_get_contents ($url);
File_put_contents (basename ($url), $c, true);