PHP get directory All files and save the results to an array of programs _php tutorial

Source: Internet
Author: User
Work sometimes encounter the need to be a directory of files in bulk processing operations, this time we need to find all the eligible files in the directory and save to a result set, and then convenient batch processing, usually to save it in an array, and then loop processing, the following will be a record of the process.

PHP gets all the files in the directory and saves the results to an array

foreach (Glob (". *") as $d) {

$tmp =explode (".", $d);

$k =end ($tmp);

If it is a file, and a file with the suffix named jpg png

if (Is_file ($d) &&in_array ($k, array ("JPG", "png"))) {

$files []= $d;

}

}

echo "

";p Rint_r ($files);

The above source code is to list all files in the current directory suffix jpg png, save the results to an array and then print out, this test results printed as follows:

http://www.bkjia.com/PHPjc/814677.html www.bkjia.com true http://www.bkjia.com/PHPjc/814677.html techarticle There are times when you have to work on a batch of files in a directory, and we need to find all the eligible files in that directory and save them to a ...

  • 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.