-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.index.php
118 lines (95 loc) · 2.7 KB
/
.index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Localhost</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="./.localhost/css/main.css">
</head>
<body>
<?php
// Checks to see if veiwing hidden files is enabled
if($_SERVER['QUERY_STRING']=="hidden") {
$hide="";
$ahref="./";
$atext="hide";
} else {
$hide=".";
$ahref="./?hidden";
$atext="show";
}
?>
<header role="banner" class="header">
<h1>Localhost</h1>
<nav role="navigation" class="nav">
<?php echo("<a href='$ahref' class='btn btn--$atext'>Hidden</a>"); ?>
</nav>
</header>
<table class="sortable">
<thead>
<tr>
<th></th>
<th class="col-name"><span>Name</span></th>
<th class="col-date"><span>Date <span>Modified</span></span></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
// Opens directory
$myDirectory=opendir(".");
// Gets each entry
while($entryName=readdir($myDirectory)) {
$dirArray[]=$entryName;
}
// Closes directory
closedir($myDirectory);
// Counts elements in array
$indexCount=count($dirArray);
// Sorts files
sort($dirArray);
// Loops through the array of files
for($index=0; $index < $indexCount; $index++) {
// Decides if hidden files should be displayed, based on query above.
if(substr("$dirArray[$index]", 0, 1)!=$hide) {
// Resets Variables
$favicon="";
$class="file";
// Gets File Names
$name=$dirArray[$index];
$namehref=$dirArray[$index];
// Gets Date Modified
$modtime=date("M j, Y, g:i A", filemtime($dirArray[$index]));
$timekey=date("YmdHis", filemtime($dirArray[$index]));
// Separates directories, and performs operations on those directories
if(is_dir($dirArray[$index])) {
$extn="Folder";
$size="--";
$sizekey="0";
$class="dir";
// Gets favicon.ico, and displays it, only if it exists.
if(file_exists("$namehref/favicon.ico")) {
$favicon=" style='background-image:url($namehref/favicon.ico);'";
$extn="Website";
}
// Cleans up . and .. directories
if($name=="."){$name=". (Current Directory)"; $extn="System Folder"; $favicon=" style='background-image:url($namehref/.favicon.ico);'";}
if($name==".."){$name=".. (Parent Directory)"; $extn="System Folder";}
}
// Output
echo("
<tr class='$class'>
<td></td>
<td class='col-name'><a href='./$namehref'$favicon class='name'>$name</a></td>
<td sorttable_customkey='$timekey' class='col-date'><a href='./$namehref'>$modtime</a></td>
<td></td>
</tr>");
}
}
?>
</tbody>
</table>
<script src=".localhost/js/jquery.min.js"></script>
<script src=".localhost/js/sorttable.js"></script>
</body>
</html>