This is a collection of some of the stupid code I write.
<?php
error_reporting(0);
ini_set("display_errors", 0);
function filetime_callback1($a, $b)
{
if (filemtime($a) === filemtime($b)) return 0;
return filemtime($a) < filemtime($b) ? -1 : 1;
}
function filetime_callback2($a, $b)
{
if (filesize($a) === filesize($b)) return 0;
return filesize($a) < filesize($b) ? -1 : 1;
}
$notthe = str_replace("index.php","",$_SERVER['SCRIPT_NAME']);
$bees = "Directory listing of " . $notthe;
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">';
echo '<head profile="http://gmpg.org/xfn/11">';
echo '<title>' . $bees . '</title>';
echo '<style type="text/css">BODY,TD,TH { font-family: sans-serif; font-size: 9pt;
background-color:#333333;color:#ffffff;}
a:visited{color:#ffffff}a:link{color:#ffffff}</style>';
echo '</head><body>';
echo '<div align="center">';
echo '<strong>' . $bees . '</strong><br />';
$dir = './';
$files = scandir($dir);
$smb = $_POST['submitted'];
if($smb == 'yes')
{
if($_POST['sortbysize'] == "Sort By Size")
{
usort($files, "filetime_callback2");
}
if($_POST['sortbydate'] == "Sort By Date")
{
usort($files, "filetime_callback1");
}
}
else
{
sort($files);
}
echo '<table border="1" cellspacing="0" cellpadding="3">';
foreach($files as &$lol)
{
if($lol == "index.php" || $lol == ".." || $lol == ".")
{
$lol = '';
}
else
{
echo '<tr><td>';
if(is_dir($lol))
{
echo "{###}___<a href='" . htmlentities($lol) . "'>" . $lol . " </a>___{###}";
}
else
{
echo "<a href='" . htmlentities($lol) . "'>" . $lol . " </a>";
}
echo '</tr></td>';
}
}
echo '</table>';
echo "<table border='1' cellspacing='0' cellpadding='3'>";
echo '<tr><td>';
echo "<form action='index.php' method='POST'>";
echo "<input type='hidden' value='yes' name='submitted' />";
echo "<input type='submit' name='sortbydate' value='Sort By Date' />";
echo "<input type='submit' name='sortalpha' value='Sort By Name' />";
echo "<input type='submit' name='sortbysize' value='Sort By Size' />";
echo '</form>';
echo '</tr></td></table>';
echo '</div>';
echo '</body>';
echo '</html>';
?>