. */ // And now, for something completely different... // CONFIGURATION SECTION $base_dir = dirname(__FILE__); // Filesystem path to base directory $language = "en"; // Interface language (see I18N section for available languages) $dcol1 = "#AAC0D1"; // dir list even row color $dcol2 = "#D2E2ED"; // dir list odd row color $fcol1 = "#D9E6F0"; // file list even row color $fcol2 = "#FFFFFF"; // file list odd row color // If one of the files present in the $default_pages array is present // in the current directory, load it instead ot the directory listing $show_default_page = 1; // 1 = show default, 0 = show listing $default_pages = array( "index.html", "index.htm", "index.php", "default.html", "default.htm", "default.php", "home.html", "home.htm", "home.php" ); // END CONFIGURATION SECTION // I18N - Internationalisation $strings = array( "DIRECTORY_LISTING" => "Directory listing for:", "YOU_ARE_HERE" => "You are here:", "HOME" => "Home", "BACK" => "Back", "NOT_ALLOWED" => "You are not allowed to go here:" ); switch ($language) { case 'es'; $strings = array( "DIRECTORY_LISTING" => "Listado del directorio:", "YOU_ARE_HERE" => "Estás aquí:", "HOME" => "Inicio", "BACK" => "Atrás", "NOT_ALLOWED" => "No tiene permiso para ir aquí:" ); break; case 'fr'; $strings = array( "DIRECTORY_LISTING" => "Listage du répertoire:", "YOU_ARE_HERE" => "Vous êtes ici:", "HOME" => "Accueil", "BACK" => "Retour", "NOT_ALLOWED" => "Vous n'avez pas les droits d'accès à:" ); break; default : // default language is english break; } // END I18N // FUNCTIONS /** * Return human readable sizes * * @author Aidan Lister * @version 1.1.0 * @link http://aidanlister.com/repos/v/function.size_readable.php * @param int $size Size * @param int $unit The maximum unit * @param int $retstring The return string format * @param int $si Whether to use SI prefixes */ function size_readable($size, $unit = null, $retstring = null, $si = true) { // Units if ($si === true) { $sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); $mod = 1000; } else { $sizes = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'); $mod = 1024; } $ii = count($sizes) - 1; // Max unit $unit = array_search((string) $unit, $sizes); if ($unit === null || $unit === false) { $unit = $ii; } // Return string if ($retstring === null) { $retstring = '%01.2f %s'; } // Loop $i = 0; while ($unit != $i && $size >= 1024 && $i < $ii) { $size /= $mod; $i++; } return sprintf($retstring, $size, $sizes[$i]); } function print_navigation($dir) { global $base_dir, $strings; // Show breadcrumb print($strings["YOU_ARE_HERE"] . " "); $this_dir = str_replace($base_dir, ".", $dir); $folders = explode("/", $this_dir); foreach ($folders as $folder) { $linkstring .= $folder."/"; if ($folder == ".") $folder = $strings["HOME"]; // Replace dot with name print(''.$folder.' / '); } print('
'); // Show Back link print('< '.$strings["BACK"].''); } // END FUNCTIONS if (!isset($_GET['d'])) { $the_dir = $base_dir; $is_subdir = 0; } else { $the_dir = realpath("./".$_GET['d']); $is_subdir = 1; } //echo "#$the_dir# => #".realpath($the_dir)."#
"; // Check if the_dir is a subdirectory of base_dir if (strlen($the_dir >= $base_dir) && substr($the_dir, 0, strlen($base_dir)) == $base_dir) { // it's OK } else { //echo "WRONG_DIR
"; $wrong_dir = $the_dir; // Fallback to base dir $the_dir = $base_dir; $is_subdir = 0; } // Open the directory if ($handle = opendir($the_dir)) { $directories = array(); $files = array(); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && substr($file, 0, 1) != "." && $file != basename($_SERVER["PHP_SELF"])) { // Put directories and files each in their own array if (is_dir($the_dir."/".$file)) { $directories[] = $file; } else { $files[] = $file; } } } closedir($handle); } // Sort the arrays by natural alphabetic order natcasesort($directories); natcasesort($files); // Print the list ?> <?php echo dirname($_SERVER['PHP_SELF']);?>


'.$strings["NOT_ALLOWED"].' "'.$wrong_dir.'"'); } if ($is_subdir) { print_navigation($the_dir); } $fl = 0; print(''); foreach ($directories as $dir) { if ($fl == 1) { $fl = 0; $bg = $dcol1; } else { $fl = 1; $bg = $dcol2; } print(''); } $fl = 0; foreach ($files as $file) { if ($fl == 1) { $fl = 0; $bg = $fcol1; } else { $fl = 1; $bg = $fcol2; } if (in_array($file, $default_pages) && $show_default_page == 1) { // if the file is in the $default_pages array and $show_default_page is true, redirect print("Redirecting to:".str_replace($base_dir, ".", $the_dir)."/".$file); print(''); } print(''); } print('
'.$dir.' [DIR]
'.$file.' '.size_readable(filesize($the_dir."/".$file)).'
'); if ($is_subdir) { print_navigation($the_dir); } ?>
Listed for you by "The Ultimate Recursive Directory Lister, Enhanced" (TURDLE) version 0.1 - by Lucas 'Basurero' Vieites