There are times when you are working on a file that needs to be processed in batches in a directory, this time we need to find all the eligible files in the directory and save them to a result set, and then make it easy to batch, usually by saving it to an array and then looping through it, and then documenting the process.
Copy Code code as follows:
<?php
PHP gets all the files in the directory and saves the results to the array
foreach (Glob ("./*") as $d) {
$tmp =explode ('. ', $d);
$k =end ($tmp);
If it is a file, and a file with a suffix named jpg png
if (Is_file ($d) &&in_array ($k, array (' jpg ', ' png ')) {
$files []= $d;
}
}
Echo ' <pre> ';p rint_r ($files);
The source code above is to list all files with the suffix jpg png in the current directory, save the results in an array and print them out, and the results of this test are printed as follows: