PHP code to list folders in a directory and make them links…


I had a vision of listing all the folders within a web directory so that they were browseable – I.E if you have a parent site with lots of sub sites, how can you create a list that you can just click on to look at them?

The Solution was a snippet of PHP code I put together based on some useful online stuff, none of which answered the problem specifically, so here it is:


$dirs = array_filter(glob(‘*’), ‘is_dir’);
foreach ($dirs as $key => $val) {
    echo “<a href=’$val’>$val</a><br>n”;
I’m quite happy with that one!
The usage is at (note: the sites found here are only for development/ test purposes and are not “live”)