Page 1 of 1

alright...can't seem to get the right way to display my menu

Posted: Mon Jun 05, 2006 4:55 pm
by danselstudios
ok, i'm trying to dynamically create a menu page that reads all my contents in a directory.
example directory:
dev/php/basicpages/ --> has these files [ index.php, tut.php, nav.php ]
dev/php/intermediate/ --> has these files [ index.php, tut.php, functions.php, classes.php ]
dev/flash/ --> has these files [ mainflash.html, index.html, movie.swf, check.swf ]
dev/flash/movie assets/ --> has these files [ nav.as, functions.as, section.swf ]

example display:
php
php/basicpages
index.php
tut.php
nav.php
php/intermediate
index.php
tut.php
functions.php
classes.php
flash
mainflash.html
index.html
movie.swf
check.swf
flash/movie assets
nav.as
functions.as
section.swf

I need help with the display of this menu so looks like this:
php
basics
index.php
tut.php
nav.php
intermediate
index.php
tut.php
functions.php
classes.php
flash
mainflash.html
index.html
movie.swf
check.swf
movie assets
nav.as
functions.as
section.swf

here is my script:
<table border="0" cellpadding="0" cellspacing="0">

Code: Select all

<?php
read_dir("."); 
function read_dir($dir) {  
   $path = opendir($dir);  
   while (false !== ($file = readdir($path))) {  
       if($file!="." && $file!=".." && $file!="menu.php" && $file!="styles.css" ) {
           if(is_file($dir."/".$file))
               $files[]=$file;
           else
               $dirs[]=$dir."/".$file;           
       }
   }
   if($dirs) {
       natcasesort($dirs);
       foreach($dirs as $dir) {
	     $dir = trim($dir,"./");
           echo '<tr><td class="subtitle">'.$dir.'</td></tr>';
           read_dir($dir);
       }
   }
   if($files) {
       natcasesort($files);
       foreach ($files as $file)
           echo '<tr><td><a href="'.$dir.'/'.$file.'">'.$file.'</a></td></tr>';
   }
   closedir($path);
}
?>
</table>

any help would be greatly appreciated and any links to tutorials would be great too. thanks

Posted: Mon Jun 05, 2006 6:16 pm
by daedalus__