How to check each sub-directory and list files in PHP? -


i trying create dynamic menu system plan on using in creating template sites create.

i tried find similar this, don't want use database.

basically idea content directory recurse creating menu each php page menu item , each directory top-level menu.

for this, trying list php files of directory , set foreach create <li>. have been successful in listing files of single directory not able list recursive directories.

this have far

<ul> <?php chdir('content');      foreach(glob('*') $directory){  $dirname=ucwords (str_replace('_', ' ', $directory));     if (is_dir($directory)){   print "<li>".$dirname."<ul>"; $mitem = glob("$directory/*.{php}", glob_brace); // print our links unordered list  foreach ($mitem $menu){ $menu= basename($menu, '.php'); $smenu=ucwords (str_replace('_', ' ', $menu)); print "<li><a href='$menu'>$smenu</a></li>"; } print '</ul></li>'; }   else { // print our links unordered list $dirname= basename($directory, '.php'); $dirname=ucwords (str_replace('_', ' ', $dirname));  print "<li><a href='$directory'>".$dirname."</a><li>";  } }   ?> </ul> 

this loop through 1 set of directories , show correct structure want except 2 things. 1) don't nested directories. 2) reason there new <li></li> after each entry not directory top directory only. can me fix code 1 , 2 resolved. can see image below result.

result


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -