Recusively list all files and sub-folders and show the results on a webpage.
<?php
// ----------------------------------------------------------
// Purpose: Recusively list all files and sub-folders.
// Some original code by mallsop.com on 05/2001.
// Updated by mallsop.com on 04/2009.
// PHP 5 or better. Tested ok on unix hosting box.
// GPL License.
// Some snippets from other php code posted online.
// ----------------------------------------------------------
function scanDirectory($dirid, $dirname, $path, $spaces) {
// id and full path
while (($file = readdir($dirid)) != false) { // loop
if (($file != ".") && ($file != "..")) { // not these (prevent out of memory error)
$dirname_full = $dirname."/".$file;
if (is_dir($dirname_full) && ($file != "cgi-bin")) { // is a directory and not cgi-bin (of which you may be denied access)
//echo "[debug $path : $file :$dirname : FOLDER $dirname_full ]<br />\n";
// exclude some dirs here
if ($file != "myhiddenfoldername") {
$return .= "$spaces<b>$file</b><br />\n";
$dirid_next = opendir($dirname_full); // was just $file
$newpath = $path."/".$file;
$nextspaces = $spaces." ";
$return .= scanDirectory($dirid_next, $dirname_full, $newpath, $nextspaces);
$nextspaces = "";
closedir($dirid_next);
} // end folder is ok to show.
$dirname_here = "";
}
else {
// isa file, so get the file extension
// echo "[debug FILE $dirname_full ]<Br>";
$break = explode(".", $file);
$file_ext = $break[1];
$file_ext_lowercase = strtolower($file_ext);
if (($file_ext_lowercase == "swf") OR ($file_ext_lowercase == "php") OR ($file_ext_lowercase == "html")) { // isa file to show