C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\heimam\dirlisting.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!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>