I'm trying to use scandir to display a select list of folders listed in a specific directory (which works fine) however, I need it to also add the child folders (if there are any) into my select list. If anyone could help me, that would be great!
This is the structure I want:
<option>folder 1</option>
<option> --child 1</option>
<option> folder 2</option>
<option> folder 3</option>
<option> --child 1</option>
<option> --child 2</option>
<option> --child 3</option>
And this is the code I have (which only shows the parent folders) which I got from this thread (Using scandir() to find folders in a directory (PHP)):
$dir = $_SERVER['DOCUMENT_ROOT']."\\folder\\";
$path = $dir;
$results = scandir($path);
$folders = array();
foreach ($results as $result) {
if ($result == '.' || $result == '..') continue;
if (is_dir($path . '/' . $result)) {
$folders[] = $result;
};
};
^^ but I need it to show the child directories also. I don't want the files, only the folders.