-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtool-load-file.php
More file actions
250 lines (234 loc) · 11.8 KB
/
tool-load-file.php
File metadata and controls
250 lines (234 loc) · 11.8 KB
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
245
246
247
248
249
250
<?php
include_once dirname(__FILE__) . "/functions.php";
include_once dirname(__FILE__) . "/auth.php";
include dirname(__FILE__) . "/conf.php"; //NOSONAR
if ($cfg->authentification_needed && !$userlogin) {
exit();
}
if (@$cfg->thumbnail_on_load && @$_COOKIE['togglethumb'] == 1) {
$_GET['thumbnail'] = 1;
}
$dir2 = PlanetbiruFileManager::path_decode(@$_GET['dir'], $cfg->rootdir);
if (!is_dir($dir2)) {
$dir2 = PlanetbiruFileManager::path_decode('base', $cfg->rootdir);
}
$arrfile = array();
$arrdir = array();
if (file_exists($dir2) && $handle = opendir($dir2)) {
$i = 0;
while (false !== ($ufile = readdir($handle))) {
$fn = "$dir2/$ufile";
if ($ufile == "." || $ufile == "..") {
continue;
}
$filetype = filetype($fn);
unset($obj);
if ($filetype == "file") {
$ft = PlanetbiruFileManager::getMIMEType($fn);
$obj['url'] = $cfg->rooturl . '/' . substr(PlanetbiruFileManager::path_encode($fn, $cfg->rootdir), 5);
$obj['path'] = PlanetbiruFileManager::path_encode($fn, $cfg->rootdir);
$obj['location'] = PlanetbiruFileManager::path_encode(dirname($fn), $cfg->rootdir);
$obj['name'] = basename($fn);
$fs = filesize($fn);
$obj['filesize'] = $fs;
if ($fs >= 1048576) {
$obj['size'] = number_format($fs / 1048576, 2, '.', '') . 'M';
} else if ($fs >= 1024) {
$obj['size'] = number_format($fs / 1024, 2, '.', '') . 'K';
} else {
$obj['size'] = $fs;
}
$obj['type'] = $ft->mime;
$obj['extension'] = $ft->extension;
$obj['permission'] = substr(sprintf('%o', fileperms($fn)), -4);
$fti = filemtime($fn);
$obj['filemtime'] = '<span title="' . date('Y-m-d H:i:s', $fti) . '">' . date('y-m-d', $fti) . '</span>';
$obj['mtime'] = $fti;
if ((stripos($obj['type'], 'image') !== false || stripos($obj['type'], 'application/x-shockwave-flash') !== false) && $obj['filesize'] <= $cfg->thumbnail_max_size) {
try {
$is = @getimagesize($fn);
if ($is) {
$obj['image_width'] = $is[0];
$obj['image_height'] = $is[1];
if (stripos($is['mime'], 'image') === 0) {
$obj['type'] = $is['mime'];
}
} else {
$obj['image_width'] = 0;
$obj['image_height'] = 0;
}
} catch (Exception $e) {
$obj['image_width'] = 0;
$obj['image_height'] = 0;
}
} else {
$obj['image_width'] = 0;
$obj['image_height'] = 0;
}
$arrfile[] = $obj;
} else if ($filetype == "dir") {
$obj['path'] = PlanetbiruFileManager::path_encode($fn, $cfg->rootdir);
$obj['location'] = PlanetbiruFileManager::path_encode(dirname($fn), $cfg->rootdir);
$obj['name'] = basename($fn);
$obj['type'] = 'dir';
$obj['permission'] = substr(sprintf('%o', fileperms($fn)), -4);
$fti = filemtime($fn);
$obj['filemtime'] = '<span title="' . date('Y-m-d H:i:s', $fti) . '">' . date('y-m-d', $fti) . '</span>';
$obj['mtime'] = $fti;
$arrdir[] = $obj;
}
}
}
$sortby = @$_GET['sortby'];
if (!in_array($sortby, array('name', 'filesize', 'type', 'permission', 'filemtime'))) {
$sortby = ''; // Set sortby ke kosong jika tidak valid
}
if ($sortby == '') {
$sortby = 'type'; // Default sortby jika kosong
}
$sortorder = @$_GET['sortorder'];
if (!in_array($sortorder, array('asc', 'desc'))) {
$sortorder = ''; // Set sortorder ke kosong jika tidak valid
}
if ($sortorder == '') {
$sortorder = 'asc'; // Default sortorder jika kosong
}
// Sort directory based on 'name' (default sorting is by 'name' in ascending order)
$_order = array();
foreach ($arrdir as $row) {
$_order[] = $row['name']; // Ambil nilai 'name' untuk pengurutan
}
array_multisort($_order, SORT_ASC, SORT_STRING, $arrdir);
// Sort files based on selected sortby field
$_order = array();
$_order2 = array();
// Remove extension before sorting for better file name sorting
$arrfilesort = $arrfile;
foreach ($arrfilesort as $key => $val) {
$pos = strripos($val['name'], ".");
if ($pos !== false) {
$arrfilesort[$key]['name'] = substr($val['name'], 0, $pos); // Hapus ekstensi untuk sorting
}
}
// Populate $_order with sorting data
foreach ($arrfilesort as $row) {
$_order[] = $row[$sortby]; // Ambil nilai dari field yang dipilih untuk pengurutan
$_order2[] = $row['name']; // Ambil nama file asli untuk pengurutan sekunder
}
// Sort files by sortby field (primary sort) and by name (secondary sort)
array_multisort($_order, ($sortorder == 'desc') ? SORT_DESC : SORT_ASC, $_order2, SORT_ASC, SORT_STRING, $arrfile);
if (!empty($arrdir) || !empty($arrfile)) {
if (@$_GET['thumbnail']) {
?>
<div class="file-list">
<ul>
<?php
$i = 0;
foreach ($arrdir as $k => $val) {
$i++;
?>
<li class="row-data-dir" data-file-name="<?php echo $val['name']; ?>" data-file-location="<?php echo $val['location']; ?>" data-file-type="dir">
<div class="thumbitem thumbdir">
<div class="thumbimage" <?php if (@$cfg->thumbnail && @$val['filesize'] <= $cfg->thumbnail_max_size) { ?>style="background-image:url('tool-thumb-image.php?filepath=<?php echo rawurlencode($val['path']); ?>&mtime=<?php echo $val['mtime']; ?>')" <?php } ?>>
<div class="thumbimage-inner"><a href="javascript:;" title="<?php echo $val['name']; ?>" onClick="return openDir('<?php echo str_replace("'", "\'", $val['path']); ?>')"><img id="imageid-<?php echo $i; ?>" src="style/images/trans96.gif" /></a></div>
</div>
<div class="thumbcheck"><input type="checkbox" class="input-checkbox fileid" data-isdir="true" name="fileid[]" id="fileid-<?php echo $i; ?>" value="<?php echo $val['path']; ?>" /></div>
<div class="thumbname"><a href="javascript:;" title="<?php echo $val['name']; ?>" onClick="return openDir('<?php echo $val['path']; ?>')"><?php echo $val['name']; ?></a></div>
</div>
</li>
<?php
}
foreach ($arrfile as $k => $val) {
$i++;
?>
<li class="row-data-file row-<?php echo ($i % 2) ? 'odd' : 'even'; ?>" data-file-url="<?php echo $val['url']; ?>" data-file-name="<?php echo $val['name']; ?>" data-file-location="<?php echo $val['location']; ?>" data-file-type="<?php echo $val['type']; ?>" data-file-size="<?php echo $val['size']; ?>" data-image-width="<?php echo $val['image_width']; ?>" data-image-height="<?php echo $val['image_height']; ?>">
<div class="thumbitem thumbfile thumbfile-<?php echo $val['extension']; ?>">
<div class="thumbimage" <?php if ($val['image_width'] > 0 && $val['image_height'] > 0 && stripos($val['type'], 'image') === 0 && $cfg->thumbnail) { ?> style="background-image:url('tool-thumb-image.php?filepath=<?php echo rawurlencode($val['path']); ?>&mtime=<?php echo $val['mtime']; ?>')" <?php } ?>>
<div class="thumbimage-inner"><a href="javascript:;" title="<?php echo $val['name']; ?>" onClick="return selectFile('<?php echo $val['url']; ?>')"><img id="imageid-<?php echo $i; ?>" src="style/images/trans96.gif" /></a></div>
</div>
<div class="thumbcheck"><input type="checkbox" class="input-checkbox fileid" data-isdir="false" data-iszip="<?php echo ($val['type'] == 'application/zip') ? 'true' : 'false'; ?>" name="fileid[]" id="fileid-<?php echo $i; ?>" value="<?php echo $val['path']; ?>" /></div>
<div class="thumbname"><a href="javascript:;" title="<?php echo $val['name']; ?>" onClick="return selectFile('<?php echo $val['url']; ?>')"><?php echo $val['name']; ?></a></div>
</div>
</li>
<?php
}
?>
</ul>
</div>
<?php
} else {
$sort_order = array();
$sort_order['type'] = 'asc';
$sort_order['name'] = 'asc';
$sort_order['filesize'] = 'asc';
$sort_order['permission'] = 'asc';
$sort_order['filemtime'] = 'asc';
if (isset($_GET['sortby']) && isset($_GET['sortorder'])) {
if ($sortorder == 'asc') {
$sort_order[$sortby] = 'desc';
} else if ($sortorder == 'desc') {
$sort_order[$sortby] = 'asc';
}
} else if (isset($_GET['sortby']) && !isset($_GET['sortorder'])) {
$sort_order[$sortby] = 'asc';
}
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="file-table table table-sm table-hover">
<thead>
<tr>
<th width="8"><input type="checkbox" name="control-fileid" id="control-fileid" class="input-checkbox checkbox-selector" value="1"></th>
<th class="sort-holder" data-sortby="type" data-sortorder="<?php echo $sort_order['type']; ?>" width="16" title="Sort by MIME Type<?php echo ($sort_order['type'] == 'desc') ? ' Descending' : ' Ascending'; ?>">Icon</th>
<th class="sort-holder" data-sortby="name" data-sortorder="<?php echo $sort_order['name']; ?>" title="Sort by File Name<?php echo ($sort_order['name'] == 'desc') ? ' Descending' : ' Ascending'; ?>">File Name</th>
<th class="sort-holder text-right" data-sortby="filesize" data-sortorder="<?php echo $sort_order['filesize']; ?>" width="60" align="right" title="Sort by File Size<?php echo ($sort_order['filesize'] == 'desc') ? ' Descending' : ' Ascending'; ?>">Size</th>
<th class="sort-holder" data-sortby="type" data-sortorder="<?php echo $sort_order['type']; ?>" width="70" title="Sort by MIME Type<?php echo ($sort_order['type'] == 'desc') ? ' Descending' : ' Ascending'; ?>">MIME Type</th>
<th class="sort-holder" data-sortby="permission" data-sortorder="<?php echo $sort_order['permission']; ?>" width="40" title="Sort by Permission<?php echo ($sort_order['permission'] == 'desc') ? ' Descending' : ' Ascending'; ?>">Perms</th>
<th class="sort-holder" data-sortby="filemtime" data-sortorder="<?php echo $sort_order['filemtime']; ?>" width="60" title="Sort by Time<?php echo ($sort_order['filemtime'] == 'desc') ? ' Descending' : ' Ascending'; ?>">Modified</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($arrdir as $k => $val) {
$i++;
?>
<tr class="row-data-dir row-<?php echo ($i % 2) ? 'odd' : 'even'; ?>" data-file-name="<?php echo $val['name']; ?>" data-file-location="<?php echo $val['location']; ?>" data-file-type="dir">
<td><input type="checkbox" class="input-checkbox fileid" data-isdir="true" name="fileid[]" id="fileid-<?php echo $i; ?>" value="<?php echo $val['path']; ?>" /></td>
<td><span class="fileicon fileicon-dir"></span></td>
<td><a href="javascript:;" onClick="return openDir('<?php echo str_replace("'", "\'", $val['path']); ?>')"><?php echo $val['name']; ?></a></td>
<td class="text-right"></td>
<td>dir</td>
<td><span class="permission-info badge badge-info"><?php echo $val['permission']; ?></span></td>
<td><?php echo $val['filemtime']; ?></td>
</tr>
<?php
}
?>
<?php
foreach ($arrfile as $k => $val) {
$i++;
?>
<tr class="row-data-file row-<?php echo ($i % 2) ? 'odd' : 'even'; ?>" data-file-url="<?php echo $val['url']; ?>" data-file-name="<?php echo $val['name']; ?>" data-file-location="<?php echo $val['location']; ?>" data-file-type="<?php echo $val['type']; ?>" data-file-size="<?php echo $val['size']; ?>" data-image-width="<?php echo $val['image_width']; ?>" data-image-height="<?php echo $val['image_height']; ?>">
<td><input type="checkbox" class="input-checkbox fileid" data-isdir="false" data-iszip="<?php echo ($val['type'] == 'application/zip') ? 'true' : 'false'; ?>" name="fileid[]" id="fileid-<?php echo $i; ?>" value="<?php echo $val['path']; ?>" /></td>
<td><span class="fileicon fileicon-<?php echo $val['extension']; ?>"></span></td>
<td><a href="javascript:;" onClick="return selectFile('<?php echo $val['url']; ?>')"><?php echo $val['name']; ?></a></td>
<td class="text-right"><?php echo $val['size']; ?></td>
<td><?php if (strlen($val['type']) > 18) {
$val['type'] = '<span title="' . $val['type'] . '">' . substr($val['type'], 0, 18) . '…</span>';
}
echo ($val['type']) ? $val['type'] : $val['extension']; ?></td>
<td><span class="permission-info badge badge-info"><?php echo $val['permission']; ?></span></td>
<td><?php echo $val['filemtime']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php
}
} else {
?>
<div class="alert alert-info">No file or directory found.</div>
<?php
}
?>