PHP DOS Tree Command Script

This PHP script scans all directories from the base directory and lists all the files found together with the file size. To change the starting directory edit $basedir = "."; If you miss the old DOS Tree command I'm sure you will find this script useful to list all the files in your web site.

<html>
<head>
<title>File List</title>
</head>
<body>
<?php 
// starting directory 
$basedir = "."; 

// function 
function listdir($basedir){ 
    if ($handle = @opendir($basedir)) { 
        while (false !== ($dir = readdir($handle))){ 
            if ($dir != '.' && $dir != '..'){
                $fn = $basedir."/".$dir; 
                if (is_dir($fn)){ 
                    listdir($fn); 
                } else {
                    echo $fn." ".filesize($fn)." bytes<br>"; //list file
                } 
            } 
        } 
        closedir($handle); 
    } 
} 
// function call 
listdir($basedir); 
?>
</body>
</html>
logo
Webmaster Tools & Resources
Blog