I am trying to make a function that scans a folder for subfolders, and then returns a numerical array with the names of these folders.
This is the code that I use for testing. As soon as I get it to print the names of folders, not just "." . and ".." for the current and previous folder everything will be fine, and I can finish the function.
<?php
function super_l_getthemes($dir="themes")
{
if ($handle = opendir($dir)) {
echo "Handle: {$handle}\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "{$file}<br>";
}
closedir($handle);
}
?>
The code above works fine and prints out the entire contents of the folder: files, subfolders and "." and ".."
but if I replaced:
while (false !== ($file = readdir($handle))) {
echo "{$file}<br>";
}
with:
while (false !== ($file = readdir($handle))) {
if(file_exists($file) && is_dir($file)){echo "{$file}";}
}
Function only prints "." and "..", not the two folder names that I would like to print.
Any help is appreciated.
source
share