<?php
    
    
/* $Id: ldir.php,v 1.4 2007/12/10 20:07:24 streamkid Exp $ */

    /* USAGE:
    *    $var = array (’foo’); where foo is the filesystem relative path where the files are relatively to script execution path. if you want the same (.) dir, ”, else the dir, ie ‘images’
    * ldir(’filesystem path’, 0, $var, ‘client relative path’); where client relative path is how it’s seen from outsie, ie apache. eg /~streamkid (WITHOUT trailing slash)
    * $ignore = array (”); any folders or directories you don’t want to list
    */
 
function ldir($path$level$struct$abs) {
        
$ignore = array (‘cgi-bin‘....htaccess‘.t3hdirectives‘‘Thumbs.db‘‘webarchive‘);
        
$dh = @opendir($path);
        while (
false !== ($file readdir($dh))) {
                if (!
in_array($file$ignore)) {
                        
$spaces str_repeat(‘ ‘, ($level*4));
                        
$struct[$level] = $abs;
                        
$url ;
                        if (
$level 0) {
                                for (
$i 0$i <= $level$i += 1) {
                                        
$url .= $struct[$i];
                                        
$url .= /;
                                    }
                                
$url .= $file;
                            }
                        else {
                                
$url .= $abs;
                                
$url .= /;
                                
$url .= $file;
                            }
                        if (
is_dir(“$path/$file“)) {
                                echo 
“$spaces $file<br/>n“;
                                
$dir .= /;
                                
$dir .= $file;
                                
ldir (“$path/$file“, ($level 1), $struct$file);
                            }
                        else {
                                echo 
“$spaces - <a href=”$url”>$file</a;
                                echo 
round(filesize(“$path/$file“)/10242);
                                echo 
“ kB<br/>n“;
                            }
                    }
            }
        
closedir($dh);
    }

?>