/*
----------------------------------------------------------------------------
DIRECTORYLISTER v0.7.01 modded by glenneroo
----------------------------------------------------------------------------
©2003-2004 Gabe Dunne
gdunne@quilime.com
You can use this without license, but I'd
love to see it in use. It has many
upgrades to be made. Download the
source here:
http://quilime.com/?p=opensourcePHP
VERSION HISTORY
----------------------------------------------------------------------------
UPDATES to version 0.7
----------------------------------------------------------------------------
- Major overhaul of how the directory is parsed
- Security Revamped
- Option to check if there's an index file, if there is, it will
automatically redirect
----------------------------------------------------------------------------
Updates to version 0.6
----------------------------------------------------------------------------
- Minor security fixes
- Ability to display full local file system
- Recognize files with more than one . in them. (test.test.test.test.txt, for
example) (Kev@virtualkev.com)
- Ability to remove excess path from the displayed path. e.g
/var/www/html/mystuff can now be displayed as just /mystuff
(Kev@virtualkev.com)
- Added an Icon Mod available for download at:
http://quilime.com/?p=opensourcePHP
----------------------------------------------------------------------------
Updates to version 0.5
----------------------------------------------------------------------------
Global Exceptions (Exclude any file or folder named something specific)
Unique Exceptions (Exclude one single file/folder)
Exception Classes (Exclude certain file formats)
----------------------------------------------------------------------------
Updates that probably will not happen, but may be available in the future as
a mod.
----------------------------------------------------------------------------
File Uploading
Password - protected folders
Statistics .log file (download counts, folder views, list of IP's)
option: tree mode (page stays the same)
----------------------------------------------------------------------------
Notes
----------------------------------------------------------------------------
My server is a Linux machine running Red Hat 9 with Apache2 and PHP 5.
I attempt to design my scripts to work on as many platforms as possible,
so if you find a bug that may be platform specific, please do not
hesitate to drop me an email.
© 2003, 2004 gdunne@quilime.com, http://quilime.com
*/
// config ////////////////////////
//
//
// Define exception files and folders.
//
$iconpath = '../dirlistericons/';// Path to the icon folder
// If you do not want to use icons, you can simply just not have an icon folder
// or you can set this variable to NULL or '';
//
// Examples:
// "./some/folder/index.php" // unique exception (hides the single file: ./some/folder/index.php )
// "./some/other/folder/" // unique exception (hides the single folder: ./some/other/folder/ )
// ".htaccess" // global exception (hides all .htaccess's)
// "somefolder/" // global exception (hides all somefolder/'s)
//
$exceptions = array( //
".htaccess",
".htpasswd",
$iconpath, // hiding the icon folder
".".$_SERVER['PHP_SELF'], // hiding this file
"index.php",
"/" // hide / for good measure
);
// define a specific file extension that you always want invisible
//
// Examples:
// "php" // excludes all *.php files
// "desc" // excludes all *.desc files
//
//
$exceptionClasses = array(
//"php", // hides all php files
//"html" // hides all html files
);
$indexFileCheck = FALSE; // check to see if an index exists
$indexFiles = array( // array of checked index files
'index.html',
'index.php'
);
$web_url = 'http://www.quilime.com'; // base url
$calcExceptions = FALSE; // Calculate file/folder exceptions into the total size? (FALSE is default)
$rowNumbers = TRUE; // Show row numbers? (TRUE is default)
//////////////////////////////////
function parent_dir($path)
{
$dirs = explode('/', substr($path,0,-1));
if (count($dirs) <= 1) // if no parent directory
{
return '/';
}
else // go one level up
{
return $dirs[count($dirs)-2].'/';
}
}
function read_directory($path)
{
global $files, $folders, $exceptionClasses, $exceptions, $web_url, $indexFileCheck, $indexFiles;
$dir_handle = @opendir('./'.$path); // directory recursion //
if(!$dir_handle) { $dir_handle = @opendir($root); $path = $root; } // if folder isn't there, go back to root
$i=0; // var used to increment $files array
$j=0; // var used to increment $folders array
while ($file = readdir($dir_handle)) // Loop through everything in the selected $path and assign the contents to an array of files and an array of folders
{
if($file != "." && $file != "..")
{
if (is_dir($path.$file))
{
$path.$file .= "/"; // add a slash to directories
}
$fileExt = ereg_replace("^.+\\.([^.]+)$", "\\1", $file);
if(in_array($fileExt, $exceptionClasses) || in_array($path.$file, $exceptions) || in_array($file, $exceptions) || in_array($path, $exceptions))
{
continue;
} // skip if exception
if($indexFileCheck)
{
if(in_array($file, $indexFiles) && $path != './') // if file is in the indexfiles array, go to the first one it finds
{
header('Location: '.$web_url.'/'.$path.$file);
}
}
if (is_dir($path.$file)) // if file is a directory, add to the $folders array, increment the counter, and continue
{
$file = preg_replace("/\//", "", $file);
$folders[$j] = $file;
$j++;
continue;
}
$files[$i] = $file; // if file, add to the $files array and increment the counter
$i++;
}
}
closedir($dir_handle); // close directory
}
// get file extension
function GetExt($ext)
{
$filetype = array(
'avi' => 'Video File',
'avi' => 'Video File',
'bat' => 'Batch File',
'css' => 'Cascading Style Sheet',
'exe' => 'Executable',
'fla' => 'Flash File',
'swf' => 'SWF Flash File',
'gif' => 'GIF Image',
'dir' => 'Director File',
'html' => 'HTML File',
'htm' => 'HTM File',
'inc' => 'Include File',
'jpg' => 'JPEG Image',
'jpeg' => 'JPEG Image',
'mov' => 'Quicktime File',
'mp3' => 'MP3 File',
'mp4' => 'MPEG 4',
'msg' => 'Email Message',
'pdf' => 'PDF Acrobat File',
'psd' => 'Photoshop File',
'php' => 'PHP File',
'ppt' => 'PowerPoint Presentation',
'txt' => 'Text Document',
'wma' => 'Windows Media Audio',
'xls' => 'Excel File',
'zip' => 'Zip File',
'ttf' => 'True Type Font',
'sql' => 'SQL File',
'rpm' => 'RedHat Package Manager File',
'doc' => 'Word Document',
'png' => 'PNG Image',
'psp' => 'Paint Shop Pro Image',
'obd' => 'Microsoft Binder',
'nrg' => 'Nero Project',
'iso' => 'ISO Image File',
'bmp' => 'Windows Bit Map',
'ini' => 'INI File',
'inf' => 'INF File',
'hlp' => 'Help File',
'reg' => 'Registry File',
'log' => 'Log File',
'chm' => 'Compiled html',
'db' => 'Database'
);
$type = isset($filetype[strtolower($ext)]) ? $filetype[$ext] : 'Undefined File Type';
return $type;
}
// format size
function formatSize($size)
{
$kb = 1024; // Kilobyte
$mb = 1024 * $kb; // Megabyte
$gb = 1024 * $mb; // Gigabyte
$tb = 1024 * $gb; // Terabyte
if($size == 0) { return "(empty)"; }
if($size < $kb) { return $size." Bytes"; }
else if($size < $mb) { return round($size/$kb,2)." kb"; }
else if($size < $gb) { return round($size/$mb,2)." mb"; }
else if($size < $tb) { return round($size/$gb,2)." gb"; }
else { return round($size/$tb,2)." tb"; }
}
// get amount of files, dirs, and formatted size
function getSize($dir)
{
global $exceptions, $exceptionClasses, $calcExceptions;
$files = 0;
$dirs = 0;
$memory = 0;
$hidden = 0;
if ($dir_handle = @opendir($dir))
{
while ($file = readdir($dir_handle))
{
if($file != "." && $file != "..")
{
$dir .= "/";
$dir = preg_replace("/\/\//", "/", $dir); // error check: makes sure there are no double slashes
if (is_dir($dir.$file)) // add a slash to directories
{
$dir.$file .= "/";
}
if(@is_dir($dir.$file))
{
if (!$calcExceptions) // skip if exception
{
if (in_array($dir, $exceptions) || in_array($file, $exceptions) || in_array($dir.$file, $exceptions))
{
continue;
}
}
$sizeBuild = getSize($dir.$file);
$files += $sizeBuild[0];
$dirs += $sizeBuild[1];
$memory += $sizeBuild[2];
$dirs++;
}
else
{
if (!$calcExceptions) // skip if exception
{
$fileExt = ereg_replace("^.+\\.([^.]+)$", "\\1", $file);
if (in_array($file, $exceptions) || in_array($fileExt, $exceptionClasses) || in_array($dir.$file, $exceptions))
{
continue;
}
}
$memory += @filesize($dir.$file);
$files++;
}
}
}
closedir($dir_handle);
}
$size[0] = $files;
$size[1] = $dirs;
$size[2] = $memory;
$size[3] = $hidden;
return $size;
}
$root = "./"; // script root directory reference
$GET_path = isset($_GET['path']) ? $_GET['path'] : NULL;
$path = NULL;
$path_dirs = explode('/', './'.$GET_path); // explode folders into array
foreach($path_dirs as $dir_list) // create legitimate path (for security)
{
$path .= (!empty($dir_list) && $dir_list != '.' && $dir_list != '..' ) ? urldecode($dir_list).'/' : '';
}
if (!is_dir($path)) // if not a real directory, stop
{
$path_parent = NULL;
$path = NULL;
read_directory($root);// recurse files
}
else
{
$path_parent = parent_dir($path); // assign parent directory
read_directory($path); // recurse files
}
?>
Notice: Undefined variable: path in /hermes/walnacweb03/walnacweb03ab/b104/pow.glenneroo/fenfire/htdocs/index.php on line 411
Notice: Undefined variable: path in /hermes/walnacweb03/walnacweb03ab/b104/pow.glenneroo/fenfire/htdocs/index.php on line 411
/
$total = getSize('.'.$path); // total size of stuff ?>
(
Notice: Undefined variable: total in /hermes/walnacweb03/walnacweb03ab/b104/pow.glenneroo/fenfire/htdocs/index.php on line 412
Notice: Trying to access array offset on value of type null in /hermes/walnacweb03/walnacweb03ab/b104/pow.glenneroo/fenfire/htdocs/index.php on line 412
folders,
Notice: Undefined variable: total in /hermes/walnacweb03/walnacweb03ab/b104/pow.glenneroo/fenfire/htdocs/index.php on line 412
Notice: Trying to access array offset on value of type null in /hermes/walnacweb03/walnacweb03ab/b104/pow.glenneroo/fenfire/htdocs/index.php on line 412
files)
|
10/22/25, 03:38pm |
if ($path_parent) //if in subdirectory, print a button row to the parent directory
{
?>
« |
|