How would I list all the files and folders in a folder alphabetically with PHP?
I used the following for the files a.txt, b.txt, c, and d.txt, Where c is a folder. The problem is that c is displayed last instead of after b.txt because it is a folder.
I’d also like to be able to check if each is either a file or folder.
<?php
$dir = opendir ("folders");
while (false !== ($file = readdir($dir))) {
echo "$file <br />";
}
?>
The power of
glob()is here to help you. Just do: