Reputation: 220
I want to loop through a directory and echo all folders. However, the foreach-loop just echo out . and ..
$dir = 'content/';
$handle = scandir($dir);
foreach ($handle as $file) {
if (is_dir($file)) { echo '<br>' . $file; }
}
Here is the content of the directory:
Upvotes: 3
Views: 619
Reputation: 94662
Correct, the only 2 Directories in that Directory are the . and .. folders. The FILES are not folders. So if you want to see the files, try
$dir = 'content/';
$handle = scandir($dir);
foreach ($handle as $file) {
if ( ! is_dir($file)) { echo '<br>' . $file; }
}
Upvotes: 1
Reputation: 4728
Have a go using this:
$dir = 'content/';
$handle = scandir($dir);
foreach ($handle as $file) {
if (is_dir($dir.'/'.$file)) { echo '<br>' . $file; }
}
Upvotes: 2