I have a piece of code that I would like to modify to list all files in folders and sub-folders in the current path. I have found several possible solutions. I tried to implement them actually, but nothing seemed to work so I am not sure if they are actually working or not or it was just me implemented them wrong. Either way this is my current code:
<?php
$currentdir = 'C:/xampp/htdocs/test/'; //change to your directory
$dir = opendir($currentdir);
echo '<select name="workout">';
$file = preg_grep('/^([^.])/', scandir($dir));
while($file = readdir($dir))
{
if ($file != "." && $file != "..") {
echo "<option value='$file'>$file</option>";
}
else {
continue;
}
}
echo '</select>';
closedir($dir);
?>
Currently this code shows results:
$currentdir
Option1
Option2
Option3
SUB-FOLDER1
SUB-FOLDER2
Can someone help me and show me how to write/rewrite the code using existing one to display files from folders and other sub-folders to look something like this:
$currentdir
Option1
Option2
Option3
SUB-FOLDER1
Option1
Option2
Option3
SUB-FOLDER2
Option1
Option2
Option3
I became really desperate for a solution and thank you all in advance.