PHP's glob() function let's you specify a pattern to search for. PHP has a great function to help you capture only the files you need. Its called glob()
glob - Find pathnames matching a pattern
Here is an example usage -
Code:
$files = array();
foreach (glob("/path/to/folder/*.txt") as $file) {
$files[] = $file;
}