View file : dirlisting.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Directory Listing</title>
<style type="text/css" media="screen">
body {
background-color: #FFF;
color: #000;
font-family: Geneva, Arial, sans-serif;
font-size: 100%;
line-height: 140%;
}
.grey1 { background-color: #CCC; }
.grey2 { background-color: #DDD; }
</style>
</head>
<body>
<br><font face="Verdana, Arial, Helvetica, Sans-Serif" font="font" size="5">Dir Listing</font><br><br>
<table border="1" cellspacing="0" cellpadding="2">
<?php
function usecolor()
{
static $colorvalue;
$trcolor1 = "grey1";
$trcolor2 = "grey2";
if($colorvalue == $trcolor1)
$colorvalue = $trcolor2;
else
$colorvalue = $trcolor1;
return($colorvalue);
}
function test()
{
$default_dir = "./";
if(!($dp = opendir($default_dir))) die("Cannot open $default_dir.");
while($file = readdir($dp)) $filenames[] = $file;
closedir($dp);
sort($filenames);
echo "<tr><th>Files</th></tr>\n";
for($i=0; $i < count($filenames); $i++)
{
if($filenames[$i] != 'listing.php' && !preg_match('/^\./',$filenames[$i]) && !is_dir($filenames[$i]))
// don't show directories, listing.php and files that start with a dot
echo "<tr><td class=\"" . usecolor() . "\"><a href=\"" . rawurlencode($filenames[$i]) . "\">". $filenames[$i] . "</a></td></tr>\n";
}
echo "<tr><th>Directories</th></tr>\n";
for($i=0; $i < count($filenames); $i++)
{
if (is_dir($filenames[$i]) && !preg_match('/^\./',$filenames[$i]))
// do show directories but not files and exclude everything that starts with a dot
echo "<tr><td class=\"" . usecolor() . "\"><a href=\"" . rawurlencode($filenames[$i]) . "\">". $filenames[$i] . "</a></td></tr>\n";
}
}
test();
?>
</table>
</body>
</html>
|