PHP has a great function to help you capture only the files you need. Its called glob()
glob - Find pathnames matching a pattern
Returns an array containing the matched files/directories, an empty array if no file matched or FALSE on error.
Here is an example usage -
$files = glob("/path/to/folder/*.txt");
This will populate the $files
variable with a list of all files matching the *.txt
pattern in the given path.
Reference -
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…