// list just text files
foreach (glob("./myfolder/*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "<br />";
}
If you want to exclude files, you could use scandir() and array_diff()
// exclude dot files and .DS_Store
$excludes = array('.', '..', '.DS_Store');
$files = array_diff(scandir('./files/img'), array('.', '..'));
foreach($files as $filename) {
echo "$filename size " . filesize($filename) . "<br />";
}
Now, if you wanted to include only certain extensions, you could do:
$files = scandir('./images/');
$allow_extensions = array('jpg', 'png', 'gif');
foreach($files as $filename) {
$file_parts = pathinfo($filename);
if (in_array($file_parts['extension'], $allow_extensions)) {
echo "$filename size " . filesize($filename) . "<br />";
}
}