-
Notifications
You must be signed in to change notification settings - Fork 0
/
DirectoryListing.php
244 lines (227 loc) · 8.11 KB
/
DirectoryListing.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php
########################################################
# Script Info
# ===========
# File: DirectoryListing.php
# Author: Ash Young (ash@evoluted.net
# Created: 20/12/03
# Modified: 27/09/04
# Website: http://evoluted.net/directorylisting.php
# Requirements: PHP
#
# Description
# ===========
# Displays all files contained within a directory in
# a well formed table, with category-image tags
#
# If you have any functions that you like to see
# implemented in this script then please just send
# an email to ash@evoluted.net
#
# Useage
# ======
#
# To change the colours display when using the script
# scroll down to set up section
#
# To use the script just upload to your server with
# the images and point your browser to the scripts
# filename
#
# SETUP
# =====
#
# Change the following variables to display what colours
# the script outputs
########################################################
error_reporting(null);
DEFINE("IMAGEROOT", "kuvat/images/"); #CHANGE /images/ TO THE PATH OF THE ASSOCIATED IMAGES
// name of folder, no starting / or ending / relative to index.php file
$HOMEDIR="intranet";
$HOMEDIR="./".$HOMEDIR."/";
$textcolor = "#FFFFFF"; #TEXT COLOUR
$bgcolor = "#535353"; #PAGE BACKGROUND COLOUR
$normalcolor = "#0066FF"; #TABLE ROW BACKGROUND COLOUR
$highlightcolor = "#006699"; #TABLE ROW BACKGROUND COLOUR WHEN HIGHLIGHTED
$headercolor = "#003366"; #TABLE HEADER BACKGROUND COLOUR
$bordercolor = "#202750"; #TABLE BORDER COLOUR
/*
<html>
<head>
<title>Directory Listings of <? echo $_SERVER["REQUEST_URI"]; ?> </title>
<style type='text/css'>
<!--
body { color: <? echo $textcolor; ?>; font: tahoma, small verdana,arial,helvetica,sans-serif; background-color: <? echo $bgcolor; ?>; }
table { font-family: tahoma, Verdana, Geneva, sans-serif; font-size: 7pt; border: 1px; border-style: solid; border-color: <? echo $bordercolor; ?>; }
.row { background-color: <? echo $normalcolor; ?>; border: 0px;}
a:link { color: <? echo $textcolor; ?>; text-decoration: none; }
a:visited { color: <? echo $textcolor; ?>; text-decoration: none; }
a:hover, a:active { color: <? echo $textcolor; ?>; text-decoration: none; }
img {border: 0;}
#bottomborder {border: <? echo $bordercolor;?>;border-style: solid;border-top-width: 0px;border-right-width: 0px;border-bottom-width: 1px;border-left-width: 0px}
.copy { text-align: center; color: <? echo $textcolor; ?>; font-family: tahoma, Verdana, Geneva, sans-serif; font-size: 7pt; text-decoration: underline; }
//-->
</style>
</head>
<body>
*/
$files=array();
$dirs=array();
$tm = TranslationManager::instance();
clearstatcache();
$curDir = $HOMEDIR;
if ( isset($_REQUEST['directory'] ) ) {
$path_parts = pathinfo($_REQUEST['directory']);
//echo "$path_parts[basename]";
/*echo $path_parts['dirname'], "<br>\n";
echo $path_parts['basename'], "<br>\n";
//echo $path_parts['extension'], "<br>\n";
*/
if ( substr_count($path_parts['dirname']."/",$HOMEDIR ) == 1 and
substr_count($path_parts['dirname']."/","../" ) == 0 // no path altering
and $path_parts['basename'] != ".." ) { // double check
$curDir = $path_parts['dirname']."/".$path_parts['basename']."/";
}
}
$PHP_SELF = basename(__FILE__);
if ($handle = opendir($curDir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != substr($PHP_SELF, -(strlen($PHP_SELF) - strrpos($PHP_SELF, "/") - 1))) {
if ( $file == ".." and $curDir == $HOMEDIR) {
continue;
}
if (filetype($curDir.$file) == "dir") {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($curDir.$file) . ".$n";
}
else {
$key = $n;
}
$dirs[$key] = $file . "/";
}
else {
//SET THE KEY ENABLING US TO SORT
$n++;
if($_REQUEST['sort']=="date") {
$key = filemtime($curDir.$file) . ".$n";
}
elseif($_REQUEST['sort']=="size") {
$key = filesize($curDir.$file) . ".$n";
}
else {
$key = $n;
}
$files[$key] = $file;
}
}
}
closedir($handle);
}
#USE THE CORRECT ALGORITHM AND SORT OUR ARRAY
if($_REQUEST['sort']=="date") {
@ksort($dirs, SORT_NUMERIC);
@ksort($files, SORT_NUMERIC);
}
elseif($_REQUEST['sort']=="size") {
@natcasesort($dirs);
@ksort($files, SORT_NUMERIC);
}
else {
@natcasesort($dirs);
@natcasesort($files);
}
#ORDER ACCORDING TO ASCENDING OR DESCENDING AS REQUESTED
if($_REQUEST['order']=="desc" && $_REQUEST['sort']!="size") {$dirs = array_reverse($dirs);}
if($_REQUEST['order']=="desc") {$files = array_reverse($files);}
$dirs = @array_values($dirs); $files = @array_values($files);
$LINKNAME = $_SERVER['PHP_SELF']."?toiminto=intranet&directory=".$curDir."&";
echo $tm->getText("Hakemisto").": ".$curDir;
echo "<table width=\"450\" border=\"0\" cellspacing=\"0\" align=\"center\"><tr bgcolor=\"$headercolor\"><td colspan=\"2\" id=\"bottomborder\">";
if($_REQUEST['sort']!="name") {
echo "<a href=\"".$LINKNAME."sort=name&order=asc\">\n";
}
else {
if($_REQUEST['order']=="desc") {
echo "<a href=\"".$LINKNAME."sort=name&order=asc\">\n";
}
else {
echo "<a href=\"".$LINKNAME."sort=name&order=desc\">\n";
}
}
echo $tm->getText("Tiedosto")."</td><td id=\"bottomborder\" width=\"50\"></a>\n";
if($_REQUEST['sort']!="size") {
echo "<a href=\"".$LINKNAME."sort=size&order=asc\">\n";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$LINKNAME."sort=size&order=asc\">\n";
}
else {
echo "<a href=\"".$LINKNAME."sort=size&order=desc\">\n";
}
}
echo $tm->getText("Koko")."</td><td id=\"bottomborder\" width=\"120\" nowrap></a>\n";
if($_REQUEST['sort']!="date") {
echo "<a href=\"".$LINKNAME."sort=date&order=asc\">\n";
}
else {
if($_REQUEST['order']=="desc") {#
echo "<a href=\"".$LINKNAME."sort=date&order=asc\">\n";
}
else {
echo "<a href=\"".$LINKNAME."sort=date&order=desc\">\n";
}
}
echo $tm->getText("Muokattu")."</a></td></tr>\n";
foreach ($dirs as $k => $v) {
if ( substr( $v,-3) == "../") {
$folderLink = $_SERVER['PHP_SELF']."?toiminto=intranet&directory=".$path_parts['dirname']."/";
}
else {
$folderLink = $_SERVER['PHP_SELF']."?toiminto=intranet&directory=".$curDir.$v ;
}
echo "\t<tr class=\"row\" onMouseOver=\"this.style.backgroundColor='$highlightcolor'; this.style.cursor='hand';\" onMouseOut=\"this.style.backgroundColor='$normalcolor';\" onClick=\"window.location.href='" .$folderLink. "';\">";
echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "folder.gif\" width=\"16\" height=\"16\" alt=\"Directory\"></td>";
echo "\t\t<td><a href=\"".$folderLink."\">" . $v . "</a></td>";
echo "\t\t<td width=\"50\" align=\"left\">-</td>";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($curDir.$v)) . "</td>";
echo "\t</tr>\n";
}
foreach ($files as $k => $v) {
switch (substr($v, -3)) {
case "jpg":
$img = "jpg.gif";
break;
case "gif":
$img = "gif.gif";
break;
case "zip":
$img = "zip.gif";
break;
case "png":
$img = "png.gif";
break;
case "avi":
$img = "move.gif";
break;
case "mpg":
$img = "move.gif";
break;
default:
$img = "what.gif";
break;
}
echo "\t<tr class=\"row\" onMouseOver=\"this.style.backgroundColor='$highlightcolor'; this.style.cursor='hand';\" onMouseOut=\"this.style.backgroundColor='$normalcolor';\" onClick=\"window.location.href='" . $curDir.$v . "';\">\r\n";
echo "\t\t<td width=\"16\"><img src=\"" . IMAGEROOT . "$img\" width=\"16\" height=\"16\" alt=\"Directory\"></td>\r\n";
echo "\t\t<td><a href=\"" . $curDir.$v . "\">" . $v . "</a></td>\r\n";
echo "\t\t<td width=\"50\" align=\"left\">" . round(filesize($curDir.$v)/1024) . "KB</td>\r\n";
echo "\t\t<td width=\"120\" align=\"left\" nowrap>" . date ("M d Y h:i:s A", filemtime($curDir.$v)) . "</td>\r\n";
echo "\t</tr>\r\n";
}
echo "</table>\n<div align=\"center\"><a href=\"http://evoluted.net/directorylisting.php\" class=\"copy\">Directory Listing Script</a>. <a href=\"http://evoluted.net/\" class=\"copy\">© 2003-2004 Ash Young</a></div>\n";
/*</body>
</html>
*/
?>