Project

General

Profile

Download (3.02 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// Fetch a list of directories and files inside a given directory
3
function get_content($dir) {
4
	$dirs  = array();
5
	$files = array();
6

    
7
	clearstatcache();
8
	$fd = @opendir($dir);
9

    
10
	while($entry = @readdir($fd)) {
11
		if($entry == ".")                 continue;
12
		if($entry == ".." && $dir == "/") continue;
13

    
14
		if(is_dir("{$dir}/{$entry}"))
15
			array_push($dirs, $entry);
16
		else
17
			array_push($files, $entry);
18
	}
19

    
20
	@closedir($fd);
21

    
22
	natsort($dirs);
23
	natsort($files);
24

    
25
	return array($dirs, $files);
26
}
27

    
28
$path = realpath(strlen($_GET['path']) > 0 ? $_GET['path'] : "/");
29
if(is_file($path))
30
	$path = dirname($path);
31

    
32
// ----- header -----
33
?>
34
<table width="100%">
35
	<tr>
36
		<td class="fbHome" width="25px" align="left">
37
			<img src="/filebrowser/images/icon_home.gif" alt="Home" title="Home" />
38
		</td>
39
		<td>&nbsp;<?=$path;?></td>
40
		<td class="fbClose" align="right">
41
			<img onClick="new Effect.Fade($('fbBrowser'));" border="0" src="/filebrowser/images/icon_cancel.gif" alt="Close" title="Close" />
42
		</td>
43
	</tr>
44
	<tr>
45
		<td id="fbCurrentDir" colspan="3" class="vexpl" align="left">
46
<?php
47

    
48
// ----- read contents -----
49
if(is_dir($path)) {
50
	list($dirs, $files) = get_content($path);
51
?>
52
			
53
		</td>
54
	</tr>
55
<?php
56
}
57
else {
58
?>
59
			Directory does not exist.
60
		</td>
61
	</tr>
62
</table>
63
<?php
64
	exit;
65
}
66

    
67
// ----- directories -----
68
foreach($dirs as $dir):
69
	$realDir = realpath("{$path}/{$dir}");
70
?>
71
	<tr>
72
		<td></td>
73
		<td class="fbDir vexpl" id="<?=$realDir;?>" align="left">
74
			<div onClick="$('fbTarget').value='<?=$realDir?>'; fbBrowse('<?=$realDir?>');">
75
				<img src="/filebrowser/images/folder_generic.gif" />
76
				&nbsp;<?=$dir;?>
77
			</div>
78
		</td>
79
		<td></td>
80
	</tr>
81
<?php
82
endforeach;
83

    
84
// ----- files -----
85
foreach($files as $file):
86
	$ext = strrchr($file, ".");
87

    
88
	    if($ext == ".css" ) $type = "code";
89
	elseif($ext == ".html") $type = "code";
90
	elseif($ext == ".xml" ) $type = "code";
91
	elseif($ext == ".rrd" ) $type = "database";
92
	elseif($ext == ".gif" ) $type = "image";
93
	elseif($ext == ".jpg" ) $type = "image";
94
	elseif($ext == ".png" ) $type = "image";
95
	elseif($ext == ".js"  ) $type = "js";
96
	elseif($ext == ".pdf" ) $type = "pdf";
97
	elseif($ext == ".inc" ) $type = "php";
98
	elseif($ext == ".php" ) $type = "php";
99
	elseif($ext == ".conf") $type = "system";
100
	elseif($ext == ".pid" ) $type = "system";
101
	elseif($ext == ".sh"  ) $type = "system";
102
	elseif($ext == ".bz2" ) $type = "zip";
103
	elseif($ext == ".gz"  ) $type = "zip";
104
	elseif($ext == ".tgz" ) $type = "zip";
105
	elseif($ext == ".zip" ) $type = "zip";
106
	else                    $type = "generic";
107

    
108
	$fqpn = "{$path}/{$file}";
109

    
110
	if(is_file($fqpn)) {
111
		$fqpn = realpath($fqpn);
112
		$size = sprintf("%.2f KiB", filesize($fqpn) / 1024);
113
	}
114
	else
115
		$size = "";
116

    
117
?>
118
	<tr>
119
		<td></td>
120
		<td class="fbFile vexpl" id="<?=$fqpn;?>" align="left">
121
			<div onClick="$('fbTarget').value='<?=$path?>/<?=$file?>'; loadFile(); new Effect.Fade($('fbBrowser'));">
122
				<img src="/filebrowser/images/file_<?=$type;?>.gif" alt="" title="">
123
				&nbsp;<?=$file;?>
124
			</div>
125
		</td>
126
		<td align="right" class="vexpl">
127
			<?=$size;?>
128
		</td>
129
	</tr>
130
<?php
131
endforeach;
132
?>
133
</table>
(2-2/2)