PHP bulk Download pictures, online Find the code, not good to make

Source: Internet
Author: User
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);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.