Searching for specific file extensions in a folder/directory (PHP)
12,925
Solution 1
glob
is pretty easy:
<?php
foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
?>
There are a few suggestions for recursive descent at the readdir
page.
Solution 2
Take a look at PHP's SPL DirectoryIterator.
Solution 3
I believe PHP's glob() function is exactly what you are looking for:
http://php.net/manual/en/function.glob.php
Author by
Admin
Updated on June 23, 2022Comments
-
Admin almost 2 years
I'm trying to design a program in PHP that would allow me to find files with specific file extensions (example .jpg, .shp etc) in a known directory which consists of multiple folders. Sample code, documentation or information about what methods I will be required to use will be much appreciated.