When Automatic Directory Indexing is switched off...

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
TheLinker
-


Joined: 05 Apr 2002
Posts: 165
Location: Oslo, Norway

PostPosted: Wed Jun 05, 2002 10:47 pm    Post subject: When Automatic Directory Indexing is switched off... Reply with quote

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...

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<?php
   $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"] );
?>
<html>
<head>
   <title>Index of <?php echo $filedir ?></title>
   <style type="text/css">
   BODY
   {
      font-size : 11px;
      color : Black;
      line-height : 12px;
      font-family : Geneva, Verdana;
   }
   H1
   {
      font-size : 18px;
      line-height : 19px;
   }
</style>
</head>

<body>
<h1>Index of <?php echo $filedir ?></h1>
<pre>
<?php

$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";
echo "<hr>\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";
}
?>
</pre>
<hr>
<b>FileInDir Indexer</b> v0.1<br>
</body>
</html>


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... :)

Regards... 8)
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Jun 06, 2002 12:24 am    Post subject: Re: When Automatic Directory Indexing is switched off... Reply with quote

Thank you for your contribution :-)
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group