How to download image files in bulk by PHP _php Tutorial

Source: Internet
Author: User
Nearly always busy, encountered a manual live, need to download some remote pictures, altogether more than 100 Zhang, if by hand a piece of Save, also too time-consuming, so the internet Google a handful, find php bulk Download image file method, The original article is about how to use PHP to bulk download images in CSS files. After the study has rewritten a bit can be used, convenient and much faster.

PHP Bulk Download image file code:

Set_time_limit (0);//Set PHP time-out
$imagesURLArray = Array_unique ($imagesURLArray);

foreach ($imagesURLArray as $imagesURL) {
Echo $imagesURL;
echo "
";
File_put_contents (basename ($imagesURL), file_get_contents ($imagesURL));
}

The principle is simple, a loop with an array of image addresses, and then use PHP's file_get_contents function to get the picture, using the File_put_contents function to save the picture.
P.S: Be sure to add the PHP time-out period Oh ~!

Attach the source code to download the images in CSS via PHP:

< PHP
/*
More & Original PHP framwork
Copyright (c) 2007-2008 Ismole Inc.
Author:kimi bkjia.com
Documentation: Download the picture in the style file, water special Mr Skinner tool
*/

Note Set PHP timeout time
Set_time_limit (0);

Note Get style file content
$styleFileContent = file_get_contents (' images/style.css ');

Note matches the URL address that needs to be downloaded
Preg_match_all ("/url\ (. *) \)/", $styleFileContent, $imagesURLArray);

Note loops need to download the address, download it individually
$imagesURLArray = Array_unique ($imagesURLArray [1]);
foreach ($imagesURLArray as $imagesURL) {
File_put_contents (basename ($imagesURL), file_get_contents ($imagesURL));
}

http://www.bkjia.com/PHPjc/364691.html www.bkjia.com true http://www.bkjia.com/PHPjc/364691.html techarticle nearly always busy, encountered a manual live, need to download some remote pictures, altogether more than 100 Zhang, if through a manual one sheet of the preservation, also too time-consuming, so the Internet goo ...

  • Related Article

    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.