Project

General

Profile

Download (3.04 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
require_once("guiconfig.inc");
4

    
5
/*
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7

    
8
*/
9
// Fetch a list of directories and files inside a given directory
10
function get_content($dir) {
11
	$dirs  = array();
12
	$files = array();
13

    
14
	clearstatcache();
15
	$fd = @opendir($dir);
16

    
17
	while ($entry = @readdir($fd)) {
18
		if ($entry == ".") {
19
			continue;
20
		}
21
		if ($entry == ".." && $dir == "/") {
22
			continue;
23
		}
24
		if (is_dir("{$dir}/{$entry}")) {
25
			array_push($dirs, $entry);
26
		} else {
27
			array_push($files, $entry);
28
		}
29
	}
30

    
31
	@closedir($fd);
32

    
33
	natsort($dirs);
34
	natsort($files);
35

    
36
	return array($dirs, $files);
37
}
38

    
39
$path = realpath(strlen($_GET['path']) > 0 ? $_GET['path'] : "/");
40
if (is_file($path)) {
41
	$path = dirname($path);
42
}
43

    
44
// ----- header -----
45
?>
46
<table width="100%">
47
	<tr>
48
		<td class="fbHome" width="25px" align="left">
49
			<img onClick="jQuery('#fbTarget').val('<?=$realDir?>'); fbBrowse('/');" src="/filebrowser/images/icon_home.gif" alt="Home" title="Home" />
50
		</td>
51
		<td><b><?=$path;?></b></td>
52
		<td class="fbClose" align="right">
53
			<img onClick="jQuery('#fbBrowser').fadeOut();" border="0" src="/filebrowser/images/icon_cancel.gif" alt="Close" title="Close" />
54
		</td>
55
	</tr>
56
	<tr>
57
		<td id="fbCurrentDir" colspan="3" class="vexpl" align="left">
58
<?php
59

    
60
// ----- read contents -----
61
if (is_dir($path)) {
62
	list($dirs, $files) = get_content($path);
63
?>
64

    
65
		</td>
66
	</tr>
67
<?php
68
} else {
69
?>
70
			Directory does not exist.
71
		</td>
72
	</tr>
73
</table>
74
<?php
75
	exit;
76
}
77

    
78
// ----- directories -----
79
foreach ($dirs as $dir):
80
	$realDir = realpath("{$path}/{$dir}");
81
?>
82
	<tr>
83
		<td></td>
84
		<td class="fbDir vexpl" id="<?=$realDir;?>" align="left">
85
			<div onClick="jQuery('#fbTarget').val('<?=$realDir?>'); fbBrowse('<?=$realDir?>');">
86
				<img src="/filebrowser/images/folder_generic.gif" />
87
				&nbsp;<?=$dir;?>
88
			</div>
89
		</td>
90
		<td></td>
91
	</tr>
92
<?php
93
endforeach;
94

    
95
// ----- files -----
96
foreach ($files as $file):
97
	$ext = strrchr($file, ".");
98

    
99
	switch ($ext) {
100
		case ".css":
101
		case ".html":
102
		case ".xml":
103
			$type = "code";
104
			break;
105
		case ".rrd":
106
			$type = "database";
107
			break;
108
		case ".gif":
109
		case ".jpg":
110
		case ".png":
111
			$type = "image";
112
			break;
113
		case ".js":
114
			$type = "js";
115
			break;
116
		case ".pdf":
117
			$type = "pdf";
118
			break;
119
		case ".inc":
120
		case ".php":
121
			$type = "php";
122
			break;
123
		case ".conf":
124
		case ".pid":
125
		case ".sh":
126
			$type = "system";
127
			break;
128
		case ".bz2":
129
		case ".gz":
130
		case ".tgz":
131
		case ".zip":
132
			$type = "zip";
133
			break;
134
		default:
135
			$type = "generic";
136
	}
137

    
138
	$fqpn = "{$path}/{$file}";
139

    
140
	if (is_file($fqpn)) {
141
		$fqpn = realpath($fqpn);
142
		$size = sprintf("%.2f KiB", filesize($fqpn) / 1024);
143
	} else {
144
		$size = "";
145
	}
146

    
147
?>
148
	<tr>
149
		<td></td>
150
		<td class="fbFile vexpl" id="<?=$fqpn;?>" align="left">
151
			<?php $filename = str_replace("//","/", "{$path}/{$file}"); ?>
152
			<div onClick="jQuery('#fbTarget').val('<?=$filename?>'); loadFile(); jQuery('#fbBrowser').fadeOut();">
153
				<img src="/filebrowser/images/file_<?=$type;?>.gif" alt="" title="">
154
				&nbsp;<?=$file;?>
155
			</div>
156
		</td>
157
		<td align="right" class="vexpl">
158
			<?=$size;?>
159
		</td>
160
	</tr>
161
<?php
162
endforeach;
163
?>
164
</table>
(2-2/2)