<?php

//This file does a directory listing similar to that generated by Apache
//Use this file if you cannot overwrite the server settings when using .htaccess with "Options +Indexes"
//Rename this file to index.php and copy it to every "Forbidden" directory which you want to be listed
//This goodie was brought to you by Lutz Tautenhahn (www.lutanho.net)

$PHP_SELF=$_SERVER['PHP_SELF']; 
$pfath_info = pathinfo($PHP_SELF);
$C=isset($_REQUEST['C']) ? $_REQUEST['C'] : "N";
$O=isset($_REQUEST['O']) ? $_REQUEST['O'] : "A";
$n=0;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of <? echo $pfath_info["dirname"]; ?></title>
</head>
<body>
<style type="text/css">
td {font-family:'Courier New'; font-size:10pt}
</style>
<?
//clearstatcache();
if ($handle = opendir('.')) 
{ while (false !== ($file = readdir($handle))) 
  { if (($file!=".")&&($file!="..")&&($file!=$pfath_info["basename"]))
    { $n++;
      $key=$n;
      if($C=="M") $key=filemtime($file).".".$n;
      elseif($C=="S")
      { if (filetype($file)=="dir") $key="0.".$file;
        else $key=(filesize($file)+1).".$n";
      }
      if (filetype($file)=="dir") $files[$key]=$file."/";
      else $files[$key]=$file;
    }
  }
  closedir($handle); 
}

if($C=="N") @natcasesort($files);
else @ksort($files, SORT_REGULAR);

if($O=="D")
{ if (isset($files)) $files = array_reverse($files);
  $O="A";
}
else $O="D";

$files = @array_values($files);

echo "<H1>Index of ".$pfath_info["dirname"]."</H1>\r\n";

echo "<table border=0>\r\n";
echo "<tr>\t<td nowrap>&nbsp;";
if($C!="N") echo "<a href=\"?C=N&O=A\">";
else echo "<a href=\"?C=N&O=".$O."\">";
echo "Name</a></td>\r\n\t<td width=160 nowrap>";

if($C!="M") echo "<a href=\"?C=M&O=A\">";
else echo "<a href=\"?C=M&O=".$O."\">";
echo "Last modified</a></td>\r\n\t<td width=60 nowrap>";

if($C!="S") echo "<a href=\"?C=S&O=A\">";
else echo "<a href=\"?C=S&O=".$O."\">";
echo "Size</a></td>\r\n";
echo "</tr>\r\n\r\n";

echo "<tr><td colspan=3><hr /></td></tr>\r\n\r\n";
echo "<tr>\t<td nowrap>&#171;<a href=\"../\">Parent Directory</a></td>\r\n";
echo "\t<td>&nbsp;</td>\r\n";
echo "\t<td>&nbsp;</td>\r\n";
echo "</tr>\r\n";
  
$n = sizeof($files);
for($i=0;$i<$n;$i++) 
{ echo "<tr>\t<td nowrap>";
  if(substr($files[$i],-1)=="/")
  { echo "&#187;<a href='".$files[$i]."'><b>".$files[$i]."</b>";
    $s="-";
    $e="";
  }
  else
  { echo "&nbsp;<a href='".$files[$i]."'>".$files[$i];
    $s=filesize($files[$i]);
    $e="";
    if ($s>=1024)
    { $s/=1024;
      $e="K";
      if ($s>=1024)
      { $s/=1024;
        $e="M";
        if ($s>=1024)
        { $s/=1024;
          $e="G";
        }
      }
      $s=round($s*10)/10;
    }
  }
  echo "</a></td>\r\n";
  echo "\t<td nowrap>".date("d-M-Y H:i", filemtime($files[$i]))."</td>\r\n";
  echo "\t<td>".$s.$e."</td>\r\n";
  echo "</tr>\r\n";
}
echo "</table>\r\n";
?>
</body>
</html>