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.
Copy the Code code as follows:
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: