I got the following code that scans directory and outputs files and sub-folders in the following format:
file1.php
folder1
file2.php
folder2
file3.php
file4.php
For my hyperlinks I need to refer to links with the number of levels. So for example: file1.php, folder1 and file4.php are all level number 1. file2.php, an folder2 is level 2, and file3.php is level 3.
Any advice on how I can use a loop counter to achieve this?
$directory = $_SERVER["DOCUMENT_ROOT"]."/files/";
function folderFleList($dir, $menu_class){
$ffs = scandir($dir);
echo "<ul class=\"".$menu_class."\">
";
foreach($ffs as $ff){
if($ff != '.' && $ff != '..'){
echo '<li class="menu-item"><a href="#" class="menu-link-level-1">'.$ff;
if(is_dir($dir.'/'.$ff)) folderFleList($dir.'/'.$ff, "menu-sublist");
echo '</a></li>';
}
}
echo "</ul>
";
}
folderFleList($directory, "menu-list");