Joined: 05 Apr 2002
Location: Oslo, Norway
|Posted: Wed Jun 05, 2002 10:47 pm Post subject: When Automatic Directory Indexing is switched off...
|I have switched off the Automatic Directory Indexing on my webserver setup... but I still want that functionality in some of my directories...
Some time ago I wrote a php script which had a similar functionality... I adjusted this script to make it work as closely as the built-in function in the Abyss.
One important difference between the built-in directory indexing and this script, is the possibility to show and change directories. I only wanted to show the files (and file information) in some of my directories...
As I received some questions regarding the above matter, I decided to post this script here. The script has been developed and tested under Windows environment, using Abyss webserver v1.0.3 and PHP v4.2.1.
Feel free to do what you want with this script... :)
First create a file called fdindexer.php and past the following code into the file...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
$slashpos = strrpos( $_SERVER["PHP_SELF"], "/" );
$phpfile = substr( $_SERVER["PHP_SELF"], $slashpos + 1, ( strlen( $_SERVER["PHP_SELF"] ) - $slashpos - 1) );
$filedir = str_replace( $phpfile, "", $_SERVER["PHP_SELF"] );
<title>Index of <?php echo $filedir ?></title>
font-size : 11px;
color : Black;
line-height : 12px;
font-family : Geneva, Verdana;
font-size : 18px;
line-height : 19px;
<h1>Index of <?php echo $filedir ?></h1>
$maxfilelen = 0;
$maxsizelen = 0;
$stack = array();
$handle = opendir("./");
while ( $file = readdir( $handle ) )
if ( $file != $phpfile && is_file( $file ) )
$filesize = filesize( $file );
$filetime = date( "d/m/Y H:i:s", filemtime( $file ) );
array_push( $stack, $file, $filesize, $filetime );
$tmpfilelen = strlen( $file );
$tmpsizelen = strlen( $filesize );
if ( $tmpfilelen > $maxfilelen )
$maxfilelen = $tmpfilelen;
if ( $tmpsizelen > $maxsizelen )
$maxsizelen = $tmpsizelen;
$totallen = $maxfilelen + $maxsizelen + 2;
echo "Name".str_repeat( " ", $totallen - 8 )."Size Date-Time\n";
for ( $i = 0; $i < count( $stack ); $i += 3 )
$filename = $stack[ $i ];
$filesize = $stack[ $i + 1 ];
$filetime = $stack[ $i + 2 ];
$space_repeat = str_repeat( " ", $totallen - strlen( $filename ) - strlen( $filesize ) );
echo "<a href='".$filename."'>".$filename."</a>".$space_repeat."".$filesize." ".$filetime."\n";
<b>FileInDir Indexer</b> v0.1<br>
Next, put this file into one of your directories... put some other files in the same directory... these other files should now be listed when the script is runned...
I can't guarantee that this script will work with your environment or setup... the code is not optimized and was made to solve one of my many function needs... :)