<?php
// OK please don't hold it against me, I have stripped my original
// down a lot ot make it easy for you to understand. But it can very
// easyly be sooped but I'll leave that up to you. If you want to see
// this in action come to www.darkestknite.com and check it out.
// The only reason i learned PHP is so I can create a directory index
// viewer with a black background, if you know of another way PLEASE
// let me know. It would save me time designing god knows what.
//
// SECURITY:WATCH OUT BECAUSE IF THE QUERY_STRING IS ../../../..
// THE PHP TAKES IT AS BACK ONE DIRECTORY, BACK ONE MORE
// AND BACK ONE MORE YET, SO SOMEONE CAN GET TO THE ROOT
// WITHOUT MUCH PROBLEM, SO DESIGN SOME KIND OF CONDITION
// AGAINST IT BEFORE USING IT.
//
while ($file = readdir($handle)) { // Extract dir content
$filelst = "$filelst,$file";// save into string
}
closedir($handle);//
$filelist = explode(",",$filelst); // Brake string up into array
sort($filelist);
// sort the array acendingly, I suggest you make your own sort because this one sux
for ($count=1;$count<count($filelist);$count++) {
print "<TR>";
$filename=$filelist[$count];
$file_path = "$dir_name/$filename";
$filesize = filesize($file_path);
// You can use another function to format this, but you get the idea.
if (is_file($file_path)) {
// fleBLK.gif is a small icon of a file (draw yourself one and use that or use anything you want)
echo "<TD><img src=fleBLK.gif height=20 width=24></TD>";
echo "<TD><A HREF=\" $dir_name/$filename\" > $filename </A></TD>";
echo "<TD>$filesize bytes</TD>";
// I suggest you change "File" to a function returning a better description or remove it
completely (make sure you take them all out though)
echo "<TD>File</TD>";
}
elseif(($filename != ".") && ($filename != "..")) {
// DirBLK.gif is a small icon of a folder (draw yourself one and use that or use anything you
want)
echo "<TD><img src=DirBLK.gif height=20 width=24></TD>";
echo "<TD><A HREF=\"$filename\" > $filename </A></TD>";
echo "<TD> dir </TD>";
// I suggest you change "Directory" to a function returning a better description or remove it
completely (make sure you take them all out though)
echo "<TD>Directory</TD>";
}
print "</TR>";
}
?>
</table>
<center><HR>Made by Dark Knite for www.darkestknite.com<BR></center>
</BODY>
</HTML>