Nearly has been very busy, encountered a manual live, need to download some remote pictures, a total of more than 100, if by hand a sheet of preservation, too time-consuming, so the internet Google A, find php bulk Download picture file method, The original article is about how to use PHP to bulk download pictures in CSS files. After the study rewritten a bit can be used, more convenient and faster.
PHP bulk Download picture file code:
Set_time_limit (0);/Set the PHP timeout time
$imagesURLArray = Array_unique ($imagesURLArray);
foreach ($imagesURLArray as $imagesURL) {
Echo $imagesURL;
echo "
";
File_put_contents (basename ($imagesURL), file_get_contents ($imagesURL));
}
The principle is very simple, through a loop containing the image address of the array, and then use the PHP file_get_contents function to get the picture, in the use of the File_put_contents function to save the picture.
P.S: Be sure to add PHP timeout time Oh ~!
Enclosed is the code for downloading the pictures in the CSS in the original text:
< PHP
/*
More & Original PHP framwork
Copyright (c) 2007-2008 Ismole Inc.
Author:kimi liehuo.net
Documentation: Download the pictures in the style file, water-specific Skinner tools
*/
Note Set the PHP timeout time
Set_time_limit (0);
Note To get the contents of the style file
$styleFileContent = file_get_contents (' images/style.css ');
The note matches the URL address that needs to be downloaded
Preg_match_all ("/url ((. *))/", $styleFileContent, $imagesURLArray);
Note Cycle need to download the address, download one by one
$imagesURLArray = Array_unique ($imagesURLArray [1]);
foreach ($imagesURLArray as $imagesURL) {
File_put_contents (basename ($imagesURL), file_get_contents ($imagesURL));
}