PX : code

Recursive directory list by David Trowbridge
Download this code


<?php

class dirTree {
  function 
displayTree($dirname) {
    
$dir dir($dirname);

    
// Display the tree
    
print "<ul>\\n\";
    print \"<li><b>$dirname</b>\\n\";
    print \"<ul>\\n\";
    $num_entries = 0;
    while($entry = $dir->read()) {
      $entries[$num_entries] = $entry;
      $num_entries++;
    }
    sort($entries);
    reset($entries);
    for($i = 0; $i < $num_entries; $i++) {
      $entry = $entries[$i];
      if($entry[0] != \".\") {
        $fullname = \"$dirname\" . \"$entry\";
        if(is_dir($fullname)) {
          // Is a directory
          $callname = \"$fullname\" . \"/\";
          $this->displayTree($callname);
        } else {
          printf(\"<li><a href=\\\"%s\\\">%s</a><br>\\n\", $fullname, $entry);
        }
      }
    }
    print \"</ul>\\n\";
  }
}

?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.