How to bulk download picture files through PHP

Source: Internet
Author: User
Tags foreach

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));

}

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.