· 6 years ago · Mar 20, 2019, 12:44 PM
1<?php
2/**
3 * H3K | Tiny File Manager
4 * CCP Programmers
5 * http://fb.com/ccpprogrammers
6 * https://github.com/prasathmani/tinyfilemanager
7 */
8// Default language
9$lang = 'en';
10// Auth with login/password (set true/false to enable/disable it)
11$use_auth = false;
12// Users: array('Username' => 'Password', 'Username2' => 'Password2', ...), Password has to encripted into MD5
13$auth_users = array(
14 'admin' => '21232f297a57a5a743894a0e4a801fc3', //admin
15 'user' => '827ccb0eea8a706c4c34a16891f84e7b', //12345
16);
17// Readonly users (usernames array)
18$readonly_users = array(
19 'user'
20);
21// Show or hide files and folders that starts with a dot
22$show_hidden_files = true;
23// Enable highlight.js (https://highlightjs.org/) on view's page
24$use_highlightjs = true;
25// highlight.js style
26$highlightjs_style = 'vs';
27// Enable ace.js (https://ace.c9.io/) on view's page
28$edit_files = true;
29// Send files though mail
30$send_mail = false;
31// Send files though mail
32$toMailId = ""; //yourmailid@mail.com
33// Default timezone for date() and time() - http://php.net/manual/en/timezones.php
34$default_timezone = 'Etc/UTC'; // UTC
35// Root path for file manager
36$root_path = $_SERVER['DOCUMENT_ROOT'];
37// Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
38// Will not working if $root_path will be outside of server document root
39$root_url = '';
40// Server hostname. Can set manually if wrong
41$http_host = $_SERVER['HTTP_HOST'];
42// input encoding for iconv
43$iconv_input_encoding = 'UTF-8';
44// date() format for file modification date
45$datetime_format = 'd.m.y H:i';
46// allowed upload file extensions
47$upload_extensions = ''; // 'gif,png,jpg'
48// show or hide the left side tree view
49$show_tree_view = false;
50//Array of folders excluded from listing
51$GLOBALS['exclude_folders'] = array(
52);
53// include user config php file
54if (defined('FM_CONFIG') && is_file(FM_CONFIG) ) {
55 include(FM_CONFIG);
56}
57//--- EDIT BELOW CAREFULLY OR DO NOT EDIT AT ALL
58// if fm included
59if (defined('FM_EMBED')) {
60 $use_auth = false;
61} else {
62 @set_time_limit(600);
63 date_default_timezone_set($default_timezone);
64 ini_set('default_charset', 'UTF-8');
65 if (version_compare(PHP_VERSION, '5.6.0', '<') && function_exists('mb_internal_encoding')) {
66 mb_internal_encoding('UTF-8');
67 }
68 if (function_exists('mb_regex_encoding')) {
69 mb_regex_encoding('UTF-8');
70 }
71 session_cache_limiter('');
72 session_name('filemanager');
73 session_start();
74}
75if (empty($auth_users)) {
76 $use_auth = false;
77}
78$is_https = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1)
79 || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https';
80// clean and check $root_path
81$root_path = rtrim($root_path, '\\/');
82$root_path = str_replace('\\', '/', $root_path);
83if (!@is_dir($root_path)) {
84 echo "<h1>Root path \"{$root_path}\" not found!</h1>";
85 exit;
86}
87// clean $root_url
88$root_url = fm_clean_path($root_url);
89// abs path for site
90defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
91defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
92defined('FM_ROOT_URL') || define('FM_ROOT_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . (!empty($root_url) ? '/' . $root_url : ''));
93defined('FM_SELF_URL') || define('FM_SELF_URL', ($is_https ? 'https' : 'http') . '://' . $http_host . $_SERVER['PHP_SELF']);
94// logout
95if (isset($_GET['logout'])) {
96 unset($_SESSION['logged']);
97 fm_redirect(FM_SELF_URL);
98}
99// Show image here
100if (isset($_GET['img'])) {
101 fm_show_image($_GET['img']);
102}
103// Auth
104if ($use_auth) {
105 if (isset($_SESSION['logged'], $auth_users[$_SESSION['logged']])) {
106 // Logged
107 } elseif (isset($_POST['fm_usr'], $_POST['fm_pwd'])) {
108 // Logging In
109 sleep(1);
110 if (isset($auth_users[$_POST['fm_usr']]) && md5($_POST['fm_pwd']) === $auth_users[$_POST['fm_usr']]) {
111 $_SESSION['logged'] = $_POST['fm_usr'];
112 fm_set_msg('You are logged in');
113 fm_redirect(FM_SELF_URL . '?p=');
114 } else {
115 unset($_SESSION['logged']);
116 fm_set_msg('Wrong password', 'error');
117 fm_redirect(FM_SELF_URL);
118 }
119 } else {
120 // Form
121 unset($_SESSION['logged']);
122 fm_show_header_login();
123 fm_show_message();
124 ?>
125 <div class="path login-form">
126 <img src="https://image.ibb.co/k92AFQ/h3k_logo_dark.png" alt="H3K File manager" style="margin:20px;">
127 <form action="" method="post">
128 <label for="fm_usr">Username</label><input type="text" id="fm_usr" name="fm_usr" value="" placeholder="Username" required><br>
129 <label for="fm_pwd">Password</label><input type="password" id="fm_pwd" name="fm_pwd" value="" placeholder="Password" required><br>
130 <input type="submit" value="Login">
131 </form>
132 </div>
133 <?php
134 fm_show_footer_login();
135 exit;
136 }
137}
138defined('FM_LANG') || define('FM_LANG', $lang);
139defined('FM_EXTENSION') || define('FM_EXTENSION', $upload_extensions);
140defined('FM_TREEVIEW') || define('FM_TREEVIEW', $show_tree_view);
141define('FM_READONLY', $use_auth && !empty($readonly_users) && isset($_SESSION['logged']) && in_array($_SESSION['logged'], $readonly_users));
142define('FM_IS_WIN', DIRECTORY_SEPARATOR == '\\');
143// always use ?p=
144if (!isset($_GET['p']) && empty($_FILES)) {
145 fm_redirect(FM_SELF_URL . '?p=');
146}
147// get path
148$p = isset($_GET['p']) ? $_GET['p'] : (isset($_POST['p']) ? $_POST['p'] : '');
149// clean path
150$p = fm_clean_path($p);
151// instead globals vars
152define('FM_PATH', $p);
153define('FM_USE_AUTH', $use_auth);
154define('FM_EDIT_FILE', $edit_files);
155defined('FM_ICONV_INPUT_ENC') || define('FM_ICONV_INPUT_ENC', $iconv_input_encoding);
156defined('FM_USE_HIGHLIGHTJS') || define('FM_USE_HIGHLIGHTJS', $use_highlightjs);
157defined('FM_HIGHLIGHTJS_STYLE') || define('FM_HIGHLIGHTJS_STYLE', $highlightjs_style);
158defined('FM_DATETIME_FORMAT') || define('FM_DATETIME_FORMAT', $datetime_format);
159unset($p, $use_auth, $iconv_input_encoding, $use_highlightjs, $highlightjs_style);
160/*************************** ACTIONS ***************************/
161//AJAX Request
162if (isset($_POST['ajax']) && !FM_READONLY) {
163 //search : get list of files from the current folder
164 if(isset($_POST['type']) && $_POST['type']=="search") {
165 $dir = $_POST['path'];
166 $response = scan($dir);
167 echo json_encode($response);
168 }
169 //Send file to mail
170 if (isset($_POST['type']) && $_POST['type']=="mail") {
171 //send mail Fn removed.
172 }
173 //backup files
174 if(isset($_POST['type']) && $_POST['type']=="backup") {
175 $file = $_POST['file'];
176 $path = $_POST['path'];
177 $date = date("dMy-His");
178 $newFile = $file.'-'.$date.'.bak';
179 copy($path.'/'.$file, $path.'/'.$newFile) or die("Unable to backup");
180 echo "Backup $newFile Created";
181 }
182 exit;
183}
184// Delete file / folder
185if (isset($_GET['del']) && !FM_READONLY) {
186 $del = $_GET['del'];
187 $del = fm_clean_path($del);
188 $del = str_replace('/', '', $del);
189 if ($del != '' && $del != '..' && $del != '.') {
190 $path = FM_ROOT_PATH;
191 if (FM_PATH != '') {
192 $path .= '/' . FM_PATH;
193 }
194 $is_dir = is_dir($path . '/' . $del);
195 if (fm_rdelete($path . '/' . $del)) {
196 $msg = $is_dir ? 'Folder <b>%s</b> deleted' : 'File <b>%s</b> deleted';
197 fm_set_msg(sprintf($msg, fm_enc($del)));
198 } else {
199 $msg = $is_dir ? 'Folder <b>%s</b> not deleted' : 'File <b>%s</b> not deleted';
200 fm_set_msg(sprintf($msg, fm_enc($del)), 'error');
201 }
202 } else {
203 fm_set_msg('Wrong file or folder name', 'error');
204 }
205 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
206}
207// Create folder
208if (isset($_GET['new']) && isset($_GET['type']) && !FM_READONLY) {
209 $new = strip_tags($_GET['new']);
210 $type = $_GET['type'];
211 $new = fm_clean_path($new);
212 $new = str_replace('/', '', $new);
213 if ($new != '' && $new != '..' && $new != '.') {
214 $path = FM_ROOT_PATH;
215 if (FM_PATH != '') {
216 $path .= '/' . FM_PATH;
217 }
218 if($_GET['type']=="file") {
219 if(!file_exists($path . '/' . $new)) {
220 @fopen($path . '/' . $new, 'w') or die('Cannot open file: '.$new);
221 fm_set_msg(sprintf('File <b>%s</b> created', fm_enc($new)));
222 } else {
223 fm_set_msg(sprintf('File <b>%s</b> already exists', fm_enc($new)), 'alert');
224 }
225 } else {
226 if (fm_mkdir($path . '/' . $new, false) === true) {
227 fm_set_msg(sprintf('Folder <b>%s</b> created', $new));
228 } elseif (fm_mkdir($path . '/' . $new, false) === $path . '/' . $new) {
229 fm_set_msg(sprintf('Folder <b>%s</b> already exists', fm_enc($new)), 'alert');
230 } else {
231 fm_set_msg(sprintf('Folder <b>%s</b> not created', fm_enc($new)), 'error');
232 }
233 }
234 } else {
235 fm_set_msg('Wrong folder name', 'error');
236 }
237 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
238}
239// Copy folder / file
240if (isset($_GET['copy'], $_GET['finish']) && !FM_READONLY) {
241 // from
242 $copy = $_GET['copy'];
243 $copy = fm_clean_path($copy);
244 // empty path
245 if ($copy == '') {
246 fm_set_msg('Source path not defined', 'error');
247 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
248 }
249 // abs path from
250 $from = FM_ROOT_PATH . '/' . $copy;
251 // abs path to
252 $dest = FM_ROOT_PATH;
253 if (FM_PATH != '') {
254 $dest .= '/' . FM_PATH;
255 }
256 $dest .= '/' . basename($from);
257 // move?
258 $move = isset($_GET['move']);
259 // copy/move
260 if ($from != $dest) {
261 $msg_from = trim(FM_PATH . '/' . basename($from), '/');
262 if ($move) {
263 $rename = fm_rename($from, $dest);
264 if ($rename) {
265 fm_set_msg(sprintf('Moved from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
266 } elseif ($rename === null) {
267 fm_set_msg('File or folder with this path already exists', 'alert');
268 } else {
269 fm_set_msg(sprintf('Error while moving from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
270 }
271 } else {
272 if (fm_rcopy($from, $dest)) {
273 fm_set_msg(sprintf('Copyied from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)));
274 } else {
275 fm_set_msg(sprintf('Error while copying from <b>%s</b> to <b>%s</b>', fm_enc($copy), fm_enc($msg_from)), 'error');
276 }
277 }
278 } else {
279 fm_set_msg('Paths must be not equal', 'alert');
280 }
281 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
282}
283// Mass copy files/ folders
284if (isset($_POST['file'], $_POST['copy_to'], $_POST['finish']) && !FM_READONLY) {
285 // from
286 $path = FM_ROOT_PATH;
287 if (FM_PATH != '') {
288 $path .= '/' . FM_PATH;
289 }
290 // to
291 $copy_to_path = FM_ROOT_PATH;
292 $copy_to = fm_clean_path($_POST['copy_to']);
293 if ($copy_to != '') {
294 $copy_to_path .= '/' . $copy_to;
295 }
296 if ($path == $copy_to_path) {
297 fm_set_msg('Paths must be not equal', 'alert');
298 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
299 }
300 if (!is_dir($copy_to_path)) {
301 if (!fm_mkdir($copy_to_path, true)) {
302 fm_set_msg('Unable to create destination folder', 'error');
303 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
304 }
305 }
306 // move?
307 $move = isset($_POST['move']);
308 // copy/move
309 $errors = 0;
310 $files = $_POST['file'];
311 if (is_array($files) && count($files)) {
312 foreach ($files as $f) {
313 if ($f != '') {
314 // abs path from
315 $from = $path . '/' . $f;
316 // abs path to
317 $dest = $copy_to_path . '/' . $f;
318 // do
319 if ($move) {
320 $rename = fm_rename($from, $dest);
321 if ($rename === false) {
322 $errors++;
323 }
324 } else {
325 if (!fm_rcopy($from, $dest)) {
326 $errors++;
327 }
328 }
329 }
330 }
331 if ($errors == 0) {
332 $msg = $move ? 'Selected files and folders moved' : 'Selected files and folders copied';
333 fm_set_msg($msg);
334 } else {
335 $msg = $move ? 'Error while moving items' : 'Error while copying items';
336 fm_set_msg($msg, 'error');
337 }
338 } else {
339 fm_set_msg('Nothing selected', 'alert');
340 }
341 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
342}
343// Rename
344if (isset($_GET['ren'], $_GET['to']) && !FM_READONLY) {
345 // old name
346 $old = $_GET['ren'];
347 $old = fm_clean_path($old);
348 $old = str_replace('/', '', $old);
349 // new name
350 $new = $_GET['to'];
351 $new = fm_clean_path($new);
352 $new = str_replace('/', '', $new);
353 // path
354 $path = FM_ROOT_PATH;
355 if (FM_PATH != '') {
356 $path .= '/' . FM_PATH;
357 }
358 // rename
359 if ($old != '' && $new != '') {
360 if (fm_rename($path . '/' . $old, $path . '/' . $new)) {
361 fm_set_msg(sprintf('Renamed from <b>%s</b> to <b>%s</b>', fm_enc($old), fm_enc($new)));
362 } else {
363 fm_set_msg(sprintf('Error while renaming from <b>%s</b> to <b>%s</b>', fm_enc($old), fm_enc($new)), 'error');
364 }
365 } else {
366 fm_set_msg('Names not set', 'error');
367 }
368 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
369}
370// Download
371if (isset($_GET['dl'])) {
372 $dl = $_GET['dl'];
373 $dl = fm_clean_path($dl);
374 $dl = str_replace('/', '', $dl);
375 $path = FM_ROOT_PATH;
376 if (FM_PATH != '') {
377 $path .= '/' . FM_PATH;
378 }
379 if ($dl != '' && is_file($path . '/' . $dl)) {
380 header('Content-Description: File Transfer');
381 header('Content-Type: application/octet-stream');
382 header('Content-Disposition: attachment; filename="' . basename($path . '/' . $dl) . '"');
383 header('Content-Transfer-Encoding: binary');
384 header('Connection: Keep-Alive');
385 header('Expires: 0');
386 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
387 header('Pragma: public');
388 header('Content-Length: ' . filesize($path . '/' . $dl));
389 readfile($path . '/' . $dl);
390 exit;
391 } else {
392 fm_set_msg('File not found', 'error');
393 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
394 }
395}
396// Upload
397if (!empty($_FILES) && !FM_READONLY) {
398 $f = $_FILES;
399 $path = FM_ROOT_PATH;
400 $ds = DIRECTORY_SEPARATOR;
401 if (FM_PATH != '') {
402 $path .= '/' . FM_PATH;
403 }
404 $errors = 0;
405 $uploads = 0;
406 $total = count($f['file']['name']);
407 $allowed = (FM_EXTENSION) ? explode(',', FM_EXTENSION) : false;
408 $filename = $f['file']['name'];
409 $tmp_name = $f['file']['tmp_name'];
410 $ext = pathinfo($filename, PATHINFO_EXTENSION);
411 $isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
412 $targetPath = $path . $ds;
413 $fullPath = $path.'/'.$_REQUEST['fullpath'];
414 $folder = substr($fullPath, 0, strrpos($fullPath, "/"));
415 if (!is_dir($folder)) {
416 $old = umask(0);
417 mkdir($folder, 0777, true);
418 umask($old);
419 }
420 if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
421 if (move_uploaded_file($tmp_name, $fullPath)) {
422 die('Successfully uploaded');
423 } else {
424 die(sprintf('Error while uploading files. Uploaded files: %s', $uploads));
425 }
426 }
427 exit();
428}
429// Mass deleting
430if (isset($_POST['group'], $_POST['delete']) && !FM_READONLY) {
431 $path = FM_ROOT_PATH;
432 if (FM_PATH != '') {
433 $path .= '/' . FM_PATH;
434 }
435 $errors = 0;
436 $files = $_POST['file'];
437 if (is_array($files) && count($files)) {
438 foreach ($files as $f) {
439 if ($f != '') {
440 $new_path = $path . '/' . $f;
441 if (!fm_rdelete($new_path)) {
442 $errors++;
443 }
444 }
445 }
446 if ($errors == 0) {
447 fm_set_msg('Selected files and folder deleted');
448 } else {
449 fm_set_msg('Error while deleting items', 'error');
450 }
451 } else {
452 fm_set_msg('Nothing selected', 'alert');
453 }
454 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
455}
456// Pack files
457if (isset($_POST['group'], $_POST['zip']) && !FM_READONLY) {
458 $path = FM_ROOT_PATH;
459 if (FM_PATH != '') {
460 $path .= '/' . FM_PATH;
461 }
462 if (!class_exists('ZipArchive')) {
463 fm_set_msg('Operations with archives are not available', 'error');
464 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
465 }
466 $files = $_POST['file'];
467 if (!empty($files)) {
468 chdir($path);
469 if (count($files) == 1) {
470 $one_file = reset($files);
471 $one_file = basename($one_file);
472 $zipname = $one_file . '_' . date('ymd_His') . '.zip';
473 } else {
474 $zipname = 'archive_' . date('ymd_His') . '.zip';
475 }
476 $zipper = new FM_Zipper();
477 $res = $zipper->create($zipname, $files);
478 if ($res) {
479 fm_set_msg(sprintf('Archive <b>%s</b> created', fm_enc($zipname)));
480 } else {
481 fm_set_msg('Archive not created', 'error');
482 }
483 } else {
484 fm_set_msg('Nothing selected', 'alert');
485 }
486 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
487}
488// Unpack
489if (isset($_GET['unzip']) && !FM_READONLY) {
490 $unzip = $_GET['unzip'];
491 $unzip = fm_clean_path($unzip);
492 $unzip = str_replace('/', '', $unzip);
493 $path = FM_ROOT_PATH;
494 if (FM_PATH != '') {
495 $path .= '/' . FM_PATH;
496 }
497 if (!class_exists('ZipArchive')) {
498 fm_set_msg('Operations with archives are not available', 'error');
499 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
500 }
501 if ($unzip != '' && is_file($path . '/' . $unzip)) {
502 $zip_path = $path . '/' . $unzip;
503 //to folder
504 $tofolder = '';
505 if (isset($_GET['tofolder'])) {
506 $tofolder = pathinfo($zip_path, PATHINFO_FILENAME);
507 if (fm_mkdir($path . '/' . $tofolder, true)) {
508 $path .= '/' . $tofolder;
509 }
510 }
511 $zipper = new FM_Zipper();
512 $res = $zipper->unzip($zip_path, $path);
513 if ($res) {
514 fm_set_msg('Archive unpacked');
515 } else {
516 fm_set_msg('Archive not unpacked', 'error');
517 }
518 } else {
519 fm_set_msg('File not found', 'error');
520 }
521 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
522}
523// Change Perms (not for Windows)
524if (isset($_POST['chmod']) && !FM_READONLY && !FM_IS_WIN) {
525 $path = FM_ROOT_PATH;
526 if (FM_PATH != '') {
527 $path .= '/' . FM_PATH;
528 }
529 $file = $_POST['chmod'];
530 $file = fm_clean_path($file);
531 $file = str_replace('/', '', $file);
532 if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
533 fm_set_msg('File not found', 'error');
534 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
535 }
536 $mode = 0;
537 if (!empty($_POST['ur'])) {
538 $mode |= 0400;
539 }
540 if (!empty($_POST['uw'])) {
541 $mode |= 0200;
542 }
543 if (!empty($_POST['ux'])) {
544 $mode |= 0100;
545 }
546 if (!empty($_POST['gr'])) {
547 $mode |= 0040;
548 }
549 if (!empty($_POST['gw'])) {
550 $mode |= 0020;
551 }
552 if (!empty($_POST['gx'])) {
553 $mode |= 0010;
554 }
555 if (!empty($_POST['or'])) {
556 $mode |= 0004;
557 }
558 if (!empty($_POST['ow'])) {
559 $mode |= 0002;
560 }
561 if (!empty($_POST['ox'])) {
562 $mode |= 0001;
563 }
564 if (@chmod($path . '/' . $file, $mode)) {
565 fm_set_msg('Permissions changed');
566 } else {
567 fm_set_msg('Permissions not changed', 'error');
568 }
569 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
570}
571/*************************** /ACTIONS ***************************/
572// get current path
573$path = FM_ROOT_PATH;
574if (FM_PATH != '') {
575 $path .= '/' . FM_PATH;
576}
577// check path
578if (!is_dir($path)) {
579 fm_redirect(FM_SELF_URL . '?p=');
580}
581// get parent folder
582$parent = fm_get_parent_path(FM_PATH);
583$objects = is_readable($path) ? scandir($path) : array();
584$folders = array();
585$files = array();
586if (is_array($objects)) {
587 foreach ($objects as $file) {
588 if ($file == '.' || $file == '..' && in_array($file, $GLOBALS['exclude_folders'])) {
589 continue;
590 }
591 if (!FM_SHOW_HIDDEN && substr($file, 0, 1) === '.') {
592 continue;
593 }
594 $new_path = $path . '/' . $file;
595 if (is_file($new_path)) {
596 $files[] = $file;
597 } elseif (is_dir($new_path) && $file != '.' && $file != '..' && !in_array($file, $GLOBALS['exclude_folders'])) {
598 $folders[] = $file;
599 }
600 }
601}
602if (!empty($files)) {
603 natcasesort($files);
604}
605if (!empty($folders)) {
606 natcasesort($folders);
607}
608// upload form
609if (isset($_GET['upload']) && !FM_READONLY) {
610 fm_show_header(); // HEADER
611 fm_show_nav_path(FM_PATH); // current path
612 ?>
613
614 <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.css" rel="stylesheet">
615 <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.4.0/min/dropzone.min.js"></script>
616 <script>
617 Dropzone.options.fileUploader={init:function(){this.on("sending",function(file){let _path=(file.fullPath)?file.fullPath:file.name;document.getElementById("fullpath").value=_path})}}
618 </script>
619 <div class="path">
620 <p><b>Uploading files</b></p>
621 <p class="break-word">Destination folder: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?></p>
622 <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]).'?p='.fm_enc(FM_PATH) ?>" class="dropzone" id="fileUploader" enctype="multipart/form-data">
623 <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
624 <input type="hidden" name="fullpath" id="fullpath" value="<?php echo fm_enc(FM_PATH) ?>">
625 <div class="fallback">
626 <input name="file" type="file" multiple />
627 </div>
628 </form>
629
630 </div>
631 <?php
632 fm_show_footer();
633 exit;
634}
635// copy form POST
636if (isset($_POST['copy']) && !FM_READONLY) {
637 $copy_files = $_POST['file'];
638 if (!is_array($copy_files) || empty($copy_files)) {
639 fm_set_msg('Nothing selected', 'alert');
640 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
641 }
642 fm_show_header(); // HEADER
643 fm_show_nav_path(FM_PATH); // current path
644 ?>
645 <div class="path">
646 <p><b>Copying</b></p>
647 <form action="" method="post">
648 <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
649 <input type="hidden" name="finish" value="1">
650 <?php
651 foreach ($copy_files as $cf) {
652 echo '<input type="hidden" name="file[]" value="' . fm_enc($cf) . '">' . PHP_EOL;
653 }
654 ?>
655 <p class="break-word">Files: <b><?php echo implode('</b>, <b>', $copy_files) ?></b></p>
656 <p class="break-word">Source folder: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?><br>
657 <label for="inp_copy_to">Destination folder:</label>
658 <?php echo FM_ROOT_PATH ?>/<input type="text" name="copy_to" id="inp_copy_to" value="<?php echo fm_enc(FM_PATH) ?>">
659 </p>
660 <p><label><input type="checkbox" name="move" value="1"> Move'</label></p>
661 <p>
662 <button type="submit" class="btn"><i class="fa fa-check-circle"></i> Copy </button>
663 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> Cancel</a></b>
664 </p>
665 </form>
666 </div>
667 <?php
668 fm_show_footer();
669 exit;
670}
671// copy form
672if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
673 $copy = $_GET['copy'];
674 $copy = fm_clean_path($copy);
675 if ($copy == '' || !file_exists(FM_ROOT_PATH . '/' . $copy)) {
676 fm_set_msg('File not found', 'error');
677 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
678 }
679 fm_show_header(); // HEADER
680 fm_show_nav_path(FM_PATH); // current path
681 ?>
682 <div class="path">
683 <p><b>Copying</b></p>
684 <p class="break-word">
685 Source path: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . $copy)) ?><br>
686 Destination folder: <?php echo fm_enc(fm_convert_win(FM_ROOT_PATH . '/' . FM_PATH)) ?>
687 </p>
688 <p>
689 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode($copy) ?>&finish=1"><i class="fa fa-check-circle"></i> Copy</a></b>
690 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode($copy) ?>&finish=1&move=1"><i class="fa fa-check-circle"></i> Move</a></b>
691 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> Cancel</a></b>
692 </p>
693 <p><i>Select folder</i></p>
694 <ul class="folders break-word">
695 <?php
696 if ($parent !== false) {
697 ?>
698 <li><a href="?p=<?php echo urlencode($parent) ?>&copy=<?php echo urlencode($copy) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></li>
699 <?php
700 }
701 foreach ($folders as $f) {
702 ?>
703 <li><a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>&copy=<?php echo urlencode($copy) ?>"><i class="fa fa-folder-o"></i> <?php echo fm_convert_win($f) ?></a></li>
704 <?php
705 }
706 ?>
707 </ul>
708 </div>
709 <?php
710 fm_show_footer();
711 exit;
712}
713// file viewer
714if (isset($_GET['view'])) {
715 $file = $_GET['view'];
716 $file = fm_clean_path($file);
717 $file = str_replace('/', '', $file);
718 if ($file == '' || !is_file($path . '/' . $file)) {
719 fm_set_msg('File not found', 'error');
720 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
721 }
722 fm_show_header(); // HEADER
723 fm_show_nav_path(FM_PATH); // current path
724 $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
725 $file_path = $path . '/' . $file;
726 $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
727 $mime_type = fm_get_mime_type($file_path);
728 $filesize = filesize($file_path);
729 $is_zip = false;
730 $is_image = false;
731 $is_audio = false;
732 $is_video = false;
733 $is_text = false;
734 $view_title = 'File';
735 $filenames = false; // for zip
736 $content = ''; // for text
737 if ($ext == 'zip') {
738 $is_zip = true;
739 $view_title = 'Archive';
740 $filenames = fm_get_zif_info($file_path);
741 } elseif (in_array($ext, fm_get_image_exts())) {
742 $is_image = true;
743 $view_title = 'Image';
744 } elseif (in_array($ext, fm_get_audio_exts())) {
745 $is_audio = true;
746 $view_title = 'Audio';
747 } elseif (in_array($ext, fm_get_video_exts())) {
748 $is_video = true;
749 $view_title = 'Video';
750 } elseif (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
751 $is_text = true;
752 $content = file_get_contents($file_path);
753 }
754 ?>
755 <div class="path">
756 <p class="break-word"><b><?php echo $view_title ?> "<?php echo fm_enc(fm_convert_win($file)) ?>"</b></p>
757 <p class="break-word">
758 Full path: <?php echo fm_enc(fm_convert_win($file_path)) ?><br>
759 File size: <?php echo fm_get_filesize($filesize) ?><?php if ($filesize >= 1000): ?> (<?php echo sprintf('%s bytes', $filesize) ?>)<?php endif; ?><br>
760 MIME-type: <?php echo $mime_type ?><br>
761 <?php
762 // ZIP info
763 if ($is_zip && $filenames !== false) {
764 $total_files = 0;
765 $total_comp = 0;
766 $total_uncomp = 0;
767 foreach ($filenames as $fn) {
768 if (!$fn['folder']) {
769 $total_files++;
770 }
771 $total_comp += $fn['compressed_size'];
772 $total_uncomp += $fn['filesize'];
773 }
774 ?>
775 Files in archive: <?php echo $total_files ?><br>
776 Total size: <?php echo fm_get_filesize($total_uncomp) ?><br>
777 Size in archive: <?php echo fm_get_filesize($total_comp) ?><br>
778 Compression: <?php echo round(($total_comp / $total_uncomp) * 100) ?>%<br>
779 <?php
780 }
781 // Image info
782 if ($is_image) {
783 $image_size = getimagesize($file_path);
784 echo 'Image sizes: ' . (isset($image_size[0]) ? $image_size[0] : '0') . ' x ' . (isset($image_size[1]) ? $image_size[1] : '0') . '<br>';
785 }
786 // Text info
787 if ($is_text) {
788 $is_utf8 = fm_is_utf8($content);
789 if (function_exists('iconv')) {
790 if (!$is_utf8) {
791 $content = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $content);
792 }
793 }
794 echo 'Charset: ' . ($is_utf8 ? 'utf-8' : '8 bit') . '<br>';
795 }
796 ?>
797 </p>
798 <p>
799 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&dl=<?php echo urlencode($file) ?>"><i class="fa fa-cloud-download"></i> Download</a></b>
800 <b><a href="<?php echo fm_enc($file_url) ?>" target="_blank"><i class="fa fa-external-link-square"></i> Open</a></b>
801 <?php
802 // ZIP actions
803 if (!FM_READONLY && $is_zip && $filenames !== false) {
804 $zip_name = pathinfo($file_path, PATHINFO_FILENAME);
805 ?>
806 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&unzip=<?php echo urlencode($file) ?>"><i class="fa fa-check-circle"></i> UnZip</a></b>
807 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>&unzip=<?php echo urlencode($file) ?>&tofolder=1" title="UnZip to <?php echo fm_enc($zip_name) ?>"><i class="fa fa-check-circle"></i>
808 UnZip to folder</a></b>
809 <?php
810 }
811 if($is_text && !FM_READONLY) {
812 ?>
813 <b><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>" class="edit-file"><i class="fa fa-pencil-square"></i> Edit</a></b>
814 <b><a href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>&env=ace" class="edit-file"><i class="fa fa-pencil-square"></i> Advanced Edit</a></b>
815 <?php }
816 if($send_mail && !FM_READONLY) {
817 ?>
818 <b><a href="javascript:mailto('<?php echo urlencode(trim(FM_ROOT_PATH.'/'.FM_PATH)) ?>','<?php echo urlencode($file) ?>')"><i class="fa fa-pencil-square"></i> Mail</a></b>
819 <?php } ?>
820 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-chevron-circle-left"></i> Back</a></b>
821 </p>
822 <?php
823 if ($is_zip) {
824 // ZIP content
825 if ($filenames !== false) {
826 echo '<code class="maxheight">';
827 foreach ($filenames as $fn) {
828 if ($fn['folder']) {
829 echo '<b>' . fm_enc($fn['name']) . '</b><br>';
830 } else {
831 echo $fn['name'] . ' (' . fm_get_filesize($fn['filesize']) . ')<br>';
832 }
833 }
834 echo '</code>';
835 } else {
836 echo '<p>Error while fetching archive info</p>';
837 }
838 } elseif ($is_image) {
839 // Image content
840 if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'bmp', 'ico'))) {
841 echo '<p><img src="' . fm_enc($file_url) . '" alt="" class="preview-img"></p>';
842 }
843 } elseif ($is_audio) {
844 // Audio content
845 echo '<p><audio src="' . fm_enc($file_url) . '" controls preload="metadata"></audio></p>';
846 } elseif ($is_video) {
847 // Video content
848 echo '<div class="preview-video"><video src="' . fm_enc($file_url) . '" width="640" height="360" controls preload="metadata"></video></div>';
849 } elseif ($is_text) {
850 if (FM_USE_HIGHLIGHTJS) {
851 // highlight
852 $hljs_classes = array(
853 'shtml' => 'xml',
854 'htaccess' => 'apache',
855 'phtml' => 'php',
856 'lock' => 'json',
857 'svg' => 'xml',
858 );
859 $hljs_class = isset($hljs_classes[$ext]) ? 'lang-' . $hljs_classes[$ext] : 'lang-' . $ext;
860 if (empty($ext) || in_array(strtolower($file), fm_get_text_names()) || preg_match('#\.min\.(css|js)$#i', $file)) {
861 $hljs_class = 'nohighlight';
862 }
863 $content = '<pre class="with-hljs"><code class="' . $hljs_class . '">' . fm_enc($content) . '</code></pre>';
864 } elseif (in_array($ext, array('php', 'php4', 'php5', 'phtml', 'phps'))) {
865 // php highlight
866 $content = highlight_string($content, true);
867 } else {
868 $content = '<pre>' . fm_enc($content) . '</pre>';
869 }
870 echo $content;
871 }
872 ?>
873 </div>
874 <?php
875 fm_show_footer();
876 exit;
877}
878// file editor
879if (isset($_GET['edit'])) {
880 $file = $_GET['edit'];
881 $file = fm_clean_path($file);
882 $file = str_replace('/', '', $file);
883 if ($file == '' || !is_file($path . '/' . $file)) {
884 fm_set_msg('File not found', 'error');
885 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
886 }
887 fm_show_header(); // HEADER
888 fm_show_nav_path(FM_PATH); // current path
889 $file_url = FM_ROOT_URL . fm_convert_win((FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file);
890 $file_path = $path . '/' . $file;
891 //normal editer
892 $isNormalEditor = true;
893 if(isset($_GET['env'])) {
894 if($_GET['env'] == "ace") {
895 $isNormalEditor = false;
896 }
897 }
898 //Save File
899 if(isset($_POST['savedata'])) {
900 $writedata = $_POST['savedata'];
901 $fd=fopen($file_path,"w");
902 @fwrite($fd, $writedata);
903 fclose($fd);
904 fm_set_msg('File Saved Successfully', 'alert');
905 }
906 $ext = strtolower(pathinfo($file_path, PATHINFO_EXTENSION));
907 $mime_type = fm_get_mime_type($file_path);
908 $filesize = filesize($file_path);
909 $is_text = false;
910 $content = ''; // for text
911 if (in_array($ext, fm_get_text_exts()) || substr($mime_type, 0, 4) == 'text' || in_array($mime_type, fm_get_text_mimes())) {
912 $is_text = true;
913 $content = file_get_contents($file_path);
914 }
915 ?>
916 <div class="path">
917 <div class="edit-file-actions">
918 <a title="Cancel" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&view=<?php echo urlencode($file) ?>"><i class="fa fa-reply-all"></i> Cancel</a>
919 <a title="Backup" href="javascript:backup('<?php echo urlencode($path) ?>','<?php echo urlencode($file) ?>')"><i class="fa fa-database"></i> Backup</a>
920 <?php if($is_text) { ?>
921 <?php if($isNormalEditor) { ?>
922 <a title="Advanced" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>&env=ace"><i class="fa fa-paper-plane"></i> Advanced Editor</a>
923 <button type="button" name="Save" data-url="<?php echo fm_enc($file_url) ?>" onclick="edit_save(this,'nrl')"><i class="fa fa-floppy-o"></i> Save</button>
924 <?php } else { ?>
925 <a title="Plain Editor" href="?p=<?php echo urlencode(trim(FM_PATH)) ?>&edit=<?php echo urlencode($file) ?>"><i class="fa fa-text-height"></i> Plain Editor</a>
926 <button type="button" name="Save" data-url="<?php echo fm_enc($file_url) ?>" onclick="edit_save(this,'ace')"><i class="fa fa-floppy-o"></i> Save</button>
927 <?php } ?>
928 <?php } ?>
929 </div>
930 <?php
931 if ($is_text && $isNormalEditor) {
932 echo '<textarea id="normal-editor" rows="33" cols="120" style="width: 99.5%;">'. htmlspecialchars($content) .'</textarea>';
933 } elseif ($is_text) {
934 echo '<div id="editor" contenteditable="true">'. htmlspecialchars($content) .'</div>';
935 } else {
936 fm_set_msg('FILE EXTENSION HAS NOT SUPPORTED', 'error');
937 }
938 ?>
939 </div>
940 <?php
941 fm_show_footer();
942 exit;
943}
944// chmod (not for Windows)
945if (isset($_GET['chmod']) && !FM_READONLY && !FM_IS_WIN) {
946 $file = $_GET['chmod'];
947 $file = fm_clean_path($file);
948 $file = str_replace('/', '', $file);
949 if ($file == '' || (!is_file($path . '/' . $file) && !is_dir($path . '/' . $file))) {
950 fm_set_msg('File not found', 'error');
951 fm_redirect(FM_SELF_URL . '?p=' . urlencode(FM_PATH));
952 }
953 fm_show_header(); // HEADER
954 fm_show_nav_path(FM_PATH); // current path
955 $file_url = FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $file;
956 $file_path = $path . '/' . $file;
957 $mode = fileperms($path . '/' . $file);
958 ?>
959 <div class="path">
960 <p><b><?php echo 'Change Permissions'; ?></b></p>
961 <p>
962 <?php echo 'Full path:'; ?> <?php echo $file_path ?><br>
963 </p>
964 <form action="" method="post">
965 <input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
966 <input type="hidden" name="chmod" value="<?php echo fm_enc($file) ?>">
967
968 <table class="compact-table">
969 <tr>
970 <td></td>
971 <td><b>Owner</b></td>
972 <td><b>Group</b></td>
973 <td><b>Other</b></td>
974 </tr>
975 <tr>
976 <td style="text-align: right"><b>Read</b></td>
977 <td><label><input type="checkbox" name="ur" value="1"<?php echo ($mode & 00400) ? ' checked' : '' ?>></label></td>
978 <td><label><input type="checkbox" name="gr" value="1"<?php echo ($mode & 00040) ? ' checked' : '' ?>></label></td>
979 <td><label><input type="checkbox" name="or" value="1"<?php echo ($mode & 00004) ? ' checked' : '' ?>></label></td>
980 </tr>
981 <tr>
982 <td style="text-align: right"><b>Write</b></td>
983 <td><label><input type="checkbox" name="uw" value="1"<?php echo ($mode & 00200) ? ' checked' : '' ?>></label></td>
984 <td><label><input type="checkbox" name="gw" value="1"<?php echo ($mode & 00020) ? ' checked' : '' ?>></label></td>
985 <td><label><input type="checkbox" name="ow" value="1"<?php echo ($mode & 00002) ? ' checked' : '' ?>></label></td>
986 </tr>
987 <tr>
988 <td style="text-align: right"><b>Execute</b></td>
989 <td><label><input type="checkbox" name="ux" value="1"<?php echo ($mode & 00100) ? ' checked' : '' ?>></label></td>
990 <td><label><input type="checkbox" name="gx" value="1"<?php echo ($mode & 00010) ? ' checked' : '' ?>></label></td>
991 <td><label><input type="checkbox" name="ox" value="1"<?php echo ($mode & 00001) ? ' checked' : '' ?>></label></td>
992 </tr>
993 </table>
994
995 <p>
996 <button type="submit" class="btn"><i class="fa fa-check-circle"></i> Change</button>
997 <b><a href="?p=<?php echo urlencode(FM_PATH) ?>"><i class="fa fa-times-circle"></i> Cancel</a></b>
998 </p>
999
1000 </form>
1001
1002 </div>
1003 <?php
1004 fm_show_footer();
1005 exit;
1006}
1007//--- FILEMANAGER MAIN
1008fm_show_header(); // HEADER
1009fm_show_nav_path(FM_PATH); // current path
1010// messages
1011fm_show_message();
1012$num_files = count($files);
1013$num_folders = count($folders);
1014$all_files_size = 0;
1015?>
1016<form action="" method="post">
1017<input type="hidden" name="p" value="<?php echo fm_enc(FM_PATH) ?>">
1018<input type="hidden" name="group" value="1">
1019<?php if(FM_TREEVIEW) { ?>
1020<div class="file-tree-view" id="file-tree-view">
1021 <div class="tree-title">Browse</div>
1022<?php
1023//file tre view
1024 echo php_file_tree(FM_ROOT_PATH, "javascript:alert('You clicked on [link]');");
1025?>
1026</div>
1027<?php } ?>
1028<table class="table" id="main-table"><thead><tr>
1029<?php if (!FM_READONLY): ?><th style="width:3%"><label><input type="checkbox" title="Invert selection" onclick="checkbox_toggle()"></label></th><?php endif; ?>
1030<th>Name</th><th style="width:10%">Size</th>
1031<th style="width:12%">Modified</th>
1032<?php if (!FM_IS_WIN): ?><th style="width:6%">Perms</th><th style="width:10%">Owner</th><?php endif; ?>
1033<th style="width:<?php if (!FM_READONLY): ?>13<?php else: ?>6.5<?php endif; ?>%">Actions</th></tr></thead>
1034<?php
1035// link to parent folder
1036if ($parent !== false) {
1037 ?>
1038<tr><?php if (!FM_READONLY): ?><td></td><?php endif; ?><td colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>"><a href="?p=<?php echo urlencode($parent) ?>"><i class="fa fa-chevron-circle-left"></i> ..</a></td></tr>
1039<?php
1040}
1041foreach ($folders as $f) {
1042 $is_link = is_link($path . '/' . $f);
1043 $img = $is_link ? 'icon-link_folder' : 'fa fa-folder-o';
1044 $modif = date(FM_DATETIME_FORMAT, filemtime($path . '/' . $f));
1045 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
1046 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
1047 $owner = posix_getpwuid(fileowner($path . '/' . $f));
1048 $group = posix_getgrgid(filegroup($path . '/' . $f));
1049 } else {
1050 $owner = array('name' => '?');
1051 $group = array('name' => '?');
1052 }
1053 ?>
1054<tr>
1055<?php if (!FM_READONLY): ?><td><label><input type="checkbox" name="file[]" value="<?php echo fm_enc($f) ?>"></label></td><?php endif; ?>
1056<td><div class="filename"><a href="?p=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?></a><?php echo ($is_link ? ' → <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div></td>
1057<td>Folder</td><td><?php echo $modif ?></td>
1058<?php if (!FM_IS_WIN): ?>
1059<td><?php if (!FM_READONLY): ?><a title="Change Permissions" href="?p=<?php echo urlencode(FM_PATH) ?>&chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?></td>
1060<td><?php echo $owner['name'] . ':' . $group['name'] ?></td>
1061<?php endif; ?>
1062<td class="inline-actions"><?php if (!FM_READONLY): ?>
1063<a title="Delete" href="?p=<?php echo urlencode(FM_PATH) ?>&del=<?php echo urlencode($f) ?>" onclick="return confirm('Delete folder?');"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
1064<a title="Rename" href="#" onclick="rename('<?php echo fm_enc(FM_PATH) ?>', '<?php echo fm_enc($f) ?>');return false;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
1065<a title="Copy to..." href="?p=&copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o" aria-hidden="true"></i></a>
1066<?php endif; ?>
1067<a title="Direct link" href="<?php echo fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f . '/') ?>" target="_blank"><i class="fa fa-link" aria-hidden="true"></i></a>
1068</td></tr>
1069 <?php
1070 flush();
1071}
1072foreach ($files as $f) {
1073 $is_link = is_link($path . '/' . $f);
1074 $img = $is_link ? 'fa fa-file-text-o' : fm_get_file_icon_class($path . '/' . $f);
1075 $modif = date(FM_DATETIME_FORMAT, filemtime($path . '/' . $f));
1076 $filesize_raw = filesize($path . '/' . $f);
1077 $filesize = fm_get_filesize($filesize_raw);
1078 $filelink = '?p=' . urlencode(FM_PATH) . '&view=' . urlencode($f);
1079 $all_files_size += $filesize_raw;
1080 $perms = substr(decoct(fileperms($path . '/' . $f)), -4);
1081 if (function_exists('posix_getpwuid') && function_exists('posix_getgrgid')) {
1082 $owner = posix_getpwuid(fileowner($path . '/' . $f));
1083 $group = posix_getgrgid(filegroup($path . '/' . $f));
1084 } else {
1085 $owner = array('name' => '?');
1086 $group = array('name' => '?');
1087 }
1088 ?>
1089<tr>
1090<?php if (!FM_READONLY): ?><td><label><input type="checkbox" name="file[]" value="<?php echo fm_enc($f) ?>"></label></td><?php endif; ?>
1091<td><div class="filename"><a href="<?php echo $filelink ?>" title="File info"><i class="<?php echo $img ?>"></i> <?php echo fm_convert_win($f) ?></a><?php echo ($is_link ? ' → <i>' . readlink($path . '/' . $f) . '</i>' : '') ?></div></td>
1092<td><span title="<?php printf('%s bytes', $filesize_raw) ?>"><?php echo $filesize ?></span></td>
1093<td><?php echo $modif ?></td>
1094<?php if (!FM_IS_WIN): ?>
1095<td><?php if (!FM_READONLY): ?><a title="<?php echo 'Change Permissions' ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?></td>
1096<td><?php echo fm_enc($owner['name'] . ':' . $group['name']) ?></td>
1097<?php endif; ?>
1098<td class="inline-actions">
1099<?php if (!FM_READONLY): ?>
1100<a title="Delete" href="?p=<?php echo urlencode(FM_PATH) ?>&del=<?php echo urlencode($f) ?>" onclick="return confirm('Delete file?');"><i class="fa fa-trash-o"></i></a>
1101<a title="Rename" href="#" onclick="rename('<?php echo fm_enc(FM_PATH) ?>', '<?php echo fm_enc($f) ?>');return false;"><i class="fa fa-pencil-square-o"></i></a>
1102<a title="Copy to..." href="?p=<?php echo urlencode(FM_PATH) ?>&copy=<?php echo urlencode(trim(FM_PATH . '/' . $f, '/')) ?>"><i class="fa fa-files-o"></i></a>
1103<?php endif; ?>
1104<a title="Direct link" href="<?php echo fm_enc(FM_ROOT_URL . (FM_PATH != '' ? '/' . FM_PATH : '') . '/' . $f) ?>" target="_blank"><i class="fa fa-link"></i></a>
1105<a title="Download" href="?p=<?php echo urlencode(FM_PATH) ?>&dl=<?php echo urlencode($f) ?>"><i class="fa fa-download"></i></a>
1106</td></tr>
1107 <?php
1108 flush();
1109}
1110if (empty($folders) && empty($files)) {
1111 ?>
1112<tr><?php if (!FM_READONLY): ?><td></td><?php endif; ?><td colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>"><em><?php echo 'Folder is empty' ?></em></td></tr>
1113<?php
1114} else {
1115 ?>
1116<tr><?php if (!FM_READONLY): ?><td class="gray"></td><?php endif; ?><td class="gray" colspan="<?php echo !FM_IS_WIN ? '6' : '4' ?>">
1117Full size: <span title="<?php printf('%s bytes', $all_files_size) ?>"><?php echo fm_get_filesize($all_files_size) ?></span>,
1118files: <?php echo $num_files ?>,
1119folders: <?php echo $num_folders ?>
1120</td></tr>
1121<?php
1122}
1123?>
1124</table>
1125<?php if (!FM_READONLY): ?>
1126<p class="path footer-links"><a href="#/select-all" class="group-btn" onclick="select_all();return false;"><i class="fa fa-check-square"></i> Select all</a>
1127<a href="#/unselect-all" class="group-btn" onclick="unselect_all();return false;"><i class="fa fa-window-close"></i> Unselect all</a>
1128<a href="#/invert-all" class="group-btn" onclick="invert_all();return false;"><i class="fa fa-th-list"></i> Invert selection</a>
1129<input type="submit" class="hidden" name="delete" id="a-delete" value="Delete" onclick="return confirm('Delete selected files and folders?')">
1130<a href="javascript:document.getElementById('a-delete').click();" class="group-btn"><i class="fa fa-trash"></i> Delete </a>
1131<input type="submit" class="hidden" name="zip" id="a-zip" value="Zip" onclick="return confirm('Create archive?')">
1132<a href="javascript:document.getElementById('a-zip').click();" class="group-btn"><i class="fa fa-file-archive-o"></i> Zip </a>
1133<input type="submit" class="hidden" name="copy" id="a-copy" value="Copy">
1134<a href="javascript:document.getElementById('a-copy').click();" class="group-btn"><i class="fa fa-files-o"></i> Copy </a>
1135<a href="https://github.com/prasathmani/tinyfilemanager" target="_blank" class="float-right" style="color:silver">H3K | Tiny File Manager</a></p>
1136<?php endif; ?>
1137</form>
1138
1139<?php
1140fm_show_footer();
1141//--- END
1142// Functions
1143/**
1144 * Delete file or folder (recursively)
1145 * @param string $path
1146 * @return bool
1147 */
1148function fm_rdelete($path)
1149{
1150 if (is_link($path)) {
1151 return unlink($path);
1152 } elseif (is_dir($path)) {
1153 $objects = scandir($path);
1154 $ok = true;
1155 if (is_array($objects)) {
1156 foreach ($objects as $file) {
1157 if ($file != '.' && $file != '..') {
1158 if (!fm_rdelete($path . '/' . $file)) {
1159 $ok = false;
1160 }
1161 }
1162 }
1163 }
1164 return ($ok) ? rmdir($path) : false;
1165 } elseif (is_file($path)) {
1166 return unlink($path);
1167 }
1168 return false;
1169}
1170/**
1171 * Recursive chmod
1172 * @param string $path
1173 * @param int $filemode
1174 * @param int $dirmode
1175 * @return bool
1176 * @todo Will use in mass chmod
1177 */
1178function fm_rchmod($path, $filemode, $dirmode)
1179{
1180 if (is_dir($path)) {
1181 if (!chmod($path, $dirmode)) {
1182 return false;
1183 }
1184 $objects = scandir($path);
1185 if (is_array($objects)) {
1186 foreach ($objects as $file) {
1187 if ($file != '.' && $file != '..') {
1188 if (!fm_rchmod($path . '/' . $file, $filemode, $dirmode)) {
1189 return false;
1190 }
1191 }
1192 }
1193 }
1194 return true;
1195 } elseif (is_link($path)) {
1196 return true;
1197 } elseif (is_file($path)) {
1198 return chmod($path, $filemode);
1199 }
1200 return false;
1201}
1202/**
1203 * Safely rename
1204 * @param string $old
1205 * @param string $new
1206 * @return bool|null
1207 */
1208function fm_rename($old, $new)
1209{
1210 return (!file_exists($new) && file_exists($old)) ? rename($old, $new) : null;
1211}
1212/**
1213 * Copy file or folder (recursively).
1214 * @param string $path
1215 * @param string $dest
1216 * @param bool $upd Update files
1217 * @param bool $force Create folder with same names instead file
1218 * @return bool
1219 */
1220function fm_rcopy($path, $dest, $upd = true, $force = true)
1221{
1222 if (is_dir($path)) {
1223 if (!fm_mkdir($dest, $force)) {
1224 return false;
1225 }
1226 $objects = scandir($path);
1227 $ok = true;
1228 if (is_array($objects)) {
1229 foreach ($objects as $file) {
1230 if ($file != '.' && $file != '..') {
1231 if (!fm_rcopy($path . '/' . $file, $dest . '/' . $file)) {
1232 $ok = false;
1233 }
1234 }
1235 }
1236 }
1237 return $ok;
1238 } elseif (is_file($path)) {
1239 return fm_copy($path, $dest, $upd);
1240 }
1241 return false;
1242}
1243/**
1244 * Safely create folder
1245 * @param string $dir
1246 * @param bool $force
1247 * @return bool
1248 */
1249function fm_mkdir($dir, $force)
1250{
1251 if (file_exists($dir)) {
1252 if (is_dir($dir)) {
1253 return $dir;
1254 } elseif (!$force) {
1255 return false;
1256 }
1257 unlink($dir);
1258 }
1259 return mkdir($dir, 0777, true);
1260}
1261/**
1262 * Safely copy file
1263 * @param string $f1
1264 * @param string $f2
1265 * @param bool $upd
1266 * @return bool
1267 */
1268function fm_copy($f1, $f2, $upd)
1269{
1270 $time1 = filemtime($f1);
1271 if (file_exists($f2)) {
1272 $time2 = filemtime($f2);
1273 if ($time2 >= $time1 && $upd) {
1274 return false;
1275 }
1276 }
1277 $ok = copy($f1, $f2);
1278 if ($ok) {
1279 touch($f2, $time1);
1280 }
1281 return $ok;
1282}
1283/**
1284 * Get mime type
1285 * @param string $file_path
1286 * @return mixed|string
1287 */
1288function fm_get_mime_type($file_path)
1289{
1290 if (function_exists('finfo_open')) {
1291 $finfo = finfo_open(FILEINFO_MIME_TYPE);
1292 $mime = finfo_file($finfo, $file_path);
1293 finfo_close($finfo);
1294 return $mime;
1295 } elseif (function_exists('mime_content_type')) {
1296 return mime_content_type($file_path);
1297 } elseif (!stristr(ini_get('disable_functions'), 'shell_exec')) {
1298 $file = escapeshellarg($file_path);
1299 $mime = shell_exec('file -bi ' . $file);
1300 return $mime;
1301 } else {
1302 return '--';
1303 }
1304}
1305/**
1306 * HTTP Redirect
1307 * @param string $url
1308 * @param int $code
1309 */
1310function fm_redirect($url, $code = 302)
1311{
1312 header('Location: ' . $url, true, $code);
1313 exit;
1314}
1315/**
1316 * Clean path
1317 * @param string $path
1318 * @return string
1319 */
1320function fm_clean_path($path)
1321{
1322 $path = trim($path);
1323 $path = trim($path, '\\/');
1324 $path = str_replace(array('../', '..\\'), '', $path);
1325 if ($path == '..') {
1326 $path = '';
1327 }
1328 return str_replace('\\', '/', $path);
1329}
1330/**
1331 * Get parent path
1332 * @param string $path
1333 * @return bool|string
1334 */
1335function fm_get_parent_path($path)
1336{
1337 $path = fm_clean_path($path);
1338 if ($path != '') {
1339 $array = explode('/', $path);
1340 if (count($array) > 1) {
1341 $array = array_slice($array, 0, -1);
1342 return implode('/', $array);
1343 }
1344 return '';
1345 }
1346 return false;
1347}
1348/**
1349 * Get nice filesize
1350 * @param int $size
1351 * @return string
1352 */
1353function fm_get_filesize($size)
1354{
1355 if ($size < 1000) {
1356 return sprintf('%s B', $size);
1357 } elseif (($size / 1024) < 1000) {
1358 return sprintf('%s KiB', round(($size / 1024), 2));
1359 } elseif (($size / 1024 / 1024) < 1000) {
1360 return sprintf('%s MiB', round(($size / 1024 / 1024), 2));
1361 } elseif (($size / 1024 / 1024 / 1024) < 1000) {
1362 return sprintf('%s GiB', round(($size / 1024 / 1024 / 1024), 2));
1363 } else {
1364 return sprintf('%s TiB', round(($size / 1024 / 1024 / 1024 / 1024), 2));
1365 }
1366}
1367/**
1368 * Get info about zip archive
1369 * @param string $path
1370 * @return array|bool
1371 */
1372function fm_get_zif_info($path)
1373{
1374 if (function_exists('zip_open')) {
1375 $arch = zip_open($path);
1376 if ($arch) {
1377 $filenames = array();
1378 while ($zip_entry = zip_read($arch)) {
1379 $zip_name = zip_entry_name($zip_entry);
1380 $zip_folder = substr($zip_name, -1) == '/';
1381 $filenames[] = array(
1382 'name' => $zip_name,
1383 'filesize' => zip_entry_filesize($zip_entry),
1384 'compressed_size' => zip_entry_compressedsize($zip_entry),
1385 'folder' => $zip_folder
1386 //'compression_method' => zip_entry_compressionmethod($zip_entry),
1387 );
1388 }
1389 zip_close($arch);
1390 return $filenames;
1391 }
1392 }
1393 return false;
1394}
1395/**
1396 * Encode html entities
1397 * @param string $text
1398 * @return string
1399 */
1400function fm_enc($text)
1401{
1402 return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
1403}
1404/**
1405 * This function scans the files folder recursively, and builds a large array
1406 * @param string $dir
1407 * @return json
1408 */
1409function scan($dir){
1410 $files = array();
1411 $_dir = $dir;
1412 $dir = FM_ROOT_PATH.'/'.$dir;
1413 // Is there actually such a folder/file?
1414 if(file_exists($dir)){
1415 foreach(scandir($dir) as $f) {
1416 if(!$f || $f[0] == '.') {
1417 continue; // Ignore hidden files
1418 }
1419 if(is_dir($dir . '/' . $f)) {
1420 // The path is a folder
1421 $files[] = array(
1422 "name" => $f,
1423 "type" => "folder",
1424 "path" => $_dir.'/'.$f,
1425 "items" => scan($dir . '/' . $f), // Recursively get the contents of the folder
1426 );
1427 } else {
1428 // It is a file
1429 $files[] = array(
1430 "name" => $f,
1431 "type" => "file",
1432 "path" => $_dir,
1433 "size" => filesize($dir . '/' . $f) // Gets the size of this file
1434 );
1435 }
1436 }
1437 }
1438 return $files;
1439}
1440/**
1441* Scan directory and return tree view
1442* @param string $directory
1443* @param boolean $first_call
1444*/
1445function php_file_tree_dir($directory, $first_call = true) {
1446 // Recursive function called by php_file_tree() to list directories/files
1447 $php_file_tree = "";
1448 // Get and sort directories/files
1449 if( function_exists("scandir") ) $file = scandir($directory);
1450 natcasesort($file);
1451 // Make directories first
1452 $files = $dirs = array();
1453 foreach($file as $this_file) {
1454 if( is_dir("$directory/$this_file" ) ) {
1455 if(!in_array($this_file, $GLOBALS['exclude_folders'])){
1456 $dirs[] = $this_file;
1457 }
1458 } else {
1459 $files[] = $this_file;
1460 }
1461 }
1462 $file = array_merge($dirs, $files);
1463 if( count($file) > 2 ) { // Use 2 instead of 0 to account for . and .. "directories"
1464 $php_file_tree = "<ul";
1465 if( $first_call ) { $php_file_tree .= " class=\"php-file-tree\""; $first_call = false; }
1466 $php_file_tree .= ">";
1467 foreach( $file as $this_file ) {
1468 if( $this_file != "." && $this_file != ".." ) {
1469 if( is_dir("$directory/$this_file") ) {
1470 // Directory
1471 $php_file_tree .= "<li class=\"pft-directory\"><i class=\"fa fa-folder-o\"></i><a href=\"#\">" . htmlspecialchars($this_file) . "</a>";
1472 $php_file_tree .= php_file_tree_dir("$directory/$this_file", false);
1473 $php_file_tree .= "</li>";
1474 } else {
1475 // File
1476 $ext = fm_get_file_icon_class($this_file);
1477 $path = str_replace($_SERVER['DOCUMENT_ROOT'],"",$directory);
1478 $link = "?p="."$path" ."&view=".urlencode($this_file);
1479 $php_file_tree .= "<li class=\"pft-file\"><a href=\"$link\"> <i class=\"$ext\"></i>" . htmlspecialchars($this_file) . "</a></li>";
1480 }
1481 }
1482 }
1483 $php_file_tree .= "</ul>";
1484 }
1485 return $php_file_tree;
1486}
1487/**
1488 * Scan directory and render tree view
1489 * @param string $directory
1490 */
1491function php_file_tree($directory) {
1492 // Remove trailing slash
1493 $code = "";
1494 if( substr($directory, -1) == "/" ) $directory = substr($directory, 0, strlen($directory) - 1);
1495 if(function_exists('php_file_tree_dir')) {
1496 $code .= php_file_tree_dir($directory);
1497 return $code;
1498 }
1499}
1500/**
1501 * Save message in session
1502 * @param string $msg
1503 * @param string $status
1504 */
1505function fm_set_msg($msg, $status = 'ok')
1506{
1507 $_SESSION['message'] = $msg;
1508 $_SESSION['status'] = $status;
1509}
1510/**
1511 * Check if string is in UTF-8
1512 * @param string $string
1513 * @return int
1514 */
1515function fm_is_utf8($string)
1516{
1517 return preg_match('//u', $string);
1518}
1519/**
1520 * Convert file name to UTF-8 in Windows
1521 * @param string $filename
1522 * @return string
1523 */
1524function fm_convert_win($filename)
1525{
1526 if (FM_IS_WIN && function_exists('iconv')) {
1527 $filename = iconv(FM_ICONV_INPUT_ENC, 'UTF-8//IGNORE', $filename);
1528 }
1529 return $filename;
1530}
1531/**
1532 * Get CSS classname for file
1533 * @param string $path
1534 * @return string
1535 */
1536function fm_get_file_icon_class($path)
1537{
1538 // get extension
1539 $ext = strtolower(pathinfo($path, PATHINFO_EXTENSION));
1540 switch ($ext) {
1541 case 'ico': case 'gif': case 'jpg': case 'jpeg': case 'jpc': case 'jp2':
1542 case 'jpx': case 'xbm': case 'wbmp': case 'png': case 'bmp': case 'tif':
1543 case 'tiff': case 'svg':
1544 $img = 'fa fa-picture-o';
1545 break;
1546 case 'passwd': case 'ftpquota': case 'sql': case 'js': case 'json': case 'sh':
1547 case 'config': case 'twig': case 'tpl': case 'md': case 'gitignore':
1548 case 'c': case 'cpp': case 'cs': case 'py': case 'map': case 'lock': case 'dtd':
1549 $img = 'fa fa-file-code-o';
1550 break;
1551 case 'txt': case 'ini': case 'conf': case 'log': case 'htaccess':
1552 $img = 'fa fa-file-text-o';
1553 break;
1554 case 'css': case 'less': case 'sass': case 'scss':
1555 $img = 'fa fa-css3';
1556 break;
1557 case 'zip': case 'rar': case 'gz': case 'tar': case '7z':
1558 $img = 'fa fa-file-archive-o';
1559 break;
1560 case 'php': case 'php4': case 'php5': case 'phps': case 'phtml':
1561 $img = 'fa fa-code';
1562 break;
1563 case 'htm': case 'html': case 'shtml': case 'xhtml':
1564 $img = 'fa fa-html5';
1565 break;
1566 case 'xml': case 'xsl':
1567 $img = 'fa fa-file-excel-o';
1568 break;
1569 case 'wav': case 'mp3': case 'mp2': case 'm4a': case 'aac': case 'ogg':
1570 case 'oga': case 'wma': case 'mka': case 'flac': case 'ac3': case 'tds':
1571 $img = 'fa fa-music';
1572 break;
1573 case 'm3u': case 'm3u8': case 'pls': case 'cue':
1574 $img = 'fa fa-headphones';
1575 break;
1576 case 'avi': case 'mpg': case 'mpeg': case 'mp4': case 'm4v': case 'flv':
1577 case 'f4v': case 'ogm': case 'ogv': case 'mov': case 'mkv': case '3gp':
1578 case 'asf': case 'wmv':
1579 $img = 'fa fa-file-video-o';
1580 break;
1581 case 'eml': case 'msg':
1582 $img = 'fa fa-envelope-o';
1583 break;
1584 case 'xls': case 'xlsx':
1585 $img = 'fa fa-file-excel-o';
1586 break;
1587 case 'csv':
1588 $img = 'fa fa-file-text-o';
1589 break;
1590 case 'bak':
1591 $img = 'fa fa-clipboard';
1592 break;
1593 case 'doc': case 'docx':
1594 $img = 'fa fa-file-word-o';
1595 break;
1596 case 'ppt': case 'pptx':
1597 $img = 'fa fa-file-powerpoint-o';
1598 break;
1599 case 'ttf': case 'ttc': case 'otf': case 'woff':case 'woff2': case 'eot': case 'fon':
1600 $img = 'fa fa-font';
1601 break;
1602 case 'pdf':
1603 $img = 'fa fa-file-pdf-o';
1604 break;
1605 case 'psd': case 'ai': case 'eps': case 'fla': case 'swf':
1606 $img = 'fa fa-file-image-o';
1607 break;
1608 case 'exe': case 'msi':
1609 $img = 'fa fa-file-o';
1610 break;
1611 case 'bat':
1612 $img = 'fa fa-terminal';
1613 break;
1614 default:
1615 $img = 'fa fa-info-circle';
1616 }
1617 return $img;
1618}
1619/**
1620 * Get image files extensions
1621 * @return array
1622 */
1623function fm_get_image_exts()
1624{
1625 return array('ico', 'gif', 'jpg', 'jpeg', 'jpc', 'jp2', 'jpx', 'xbm', 'wbmp', 'png', 'bmp', 'tif', 'tiff', 'psd');
1626}
1627/**
1628 * Get video files extensions
1629 * @return array
1630 */
1631function fm_get_video_exts()
1632{
1633 return array('webm', 'mp4', 'm4v', 'ogm', 'ogv', 'mov');
1634}
1635/**
1636 * Get audio files extensions
1637 * @return array
1638 */
1639function fm_get_audio_exts()
1640{
1641 return array('wav', 'mp3', 'ogg', 'm4a');
1642}
1643/**
1644 * Get text file extensions
1645 * @return array
1646 */
1647function fm_get_text_exts()
1648{
1649 return array(
1650 'txt', 'css', 'ini', 'conf', 'log', 'htaccess', 'passwd', 'ftpquota', 'sql', 'js', 'json', 'sh', 'config',
1651 'php', 'php4', 'php5', 'phps', 'phtml', 'htm', 'html', 'shtml', 'xhtml', 'xml', 'xsl', 'm3u', 'm3u8', 'pls', 'cue',
1652 'eml', 'msg', 'csv', 'bat', 'twig', 'tpl', 'md', 'gitignore', 'less', 'sass', 'scss', 'c', 'cpp', 'cs', 'py',
1653 'map', 'lock', 'dtd', 'svg',
1654 );
1655}
1656/**
1657 * Get mime types of text files
1658 * @return array
1659 */
1660function fm_get_text_mimes()
1661{
1662 return array(
1663 'application/xml',
1664 'application/javascript',
1665 'application/x-javascript',
1666 'image/svg+xml',
1667 'message/rfc822',
1668 );
1669}
1670/**
1671 * Get file names of text files w/o extensions
1672 * @return array
1673 */
1674function fm_get_text_names()
1675{
1676 return array(
1677 'license',
1678 'readme',
1679 'authors',
1680 'contributors',
1681 'changelog',
1682 );
1683}
1684/**
1685 * Class to work with zip files (using ZipArchive)
1686 */
1687class FM_Zipper
1688{
1689 private $zip;
1690 public function __construct()
1691 {
1692 $this->zip = new ZipArchive();
1693 }
1694 /**
1695 * Create archive with name $filename and files $files (RELATIVE PATHS!)
1696 * @param string $filename
1697 * @param array|string $files
1698 * @return bool
1699 */
1700 public function create($filename, $files)
1701 {
1702 $res = $this->zip->open($filename, ZipArchive::CREATE);
1703 if ($res !== true) {
1704 return false;
1705 }
1706 if (is_array($files)) {
1707 foreach ($files as $f) {
1708 if (!$this->addFileOrDir($f)) {
1709 $this->zip->close();
1710 return false;
1711 }
1712 }
1713 $this->zip->close();
1714 return true;
1715 } else {
1716 if ($this->addFileOrDir($files)) {
1717 $this->zip->close();
1718 return true;
1719 }
1720 return false;
1721 }
1722 }
1723 /**
1724 * Extract archive $filename to folder $path (RELATIVE OR ABSOLUTE PATHS)
1725 * @param string $filename
1726 * @param string $path
1727 * @return bool
1728 */
1729 public function unzip($filename, $path)
1730 {
1731 $res = $this->zip->open($filename);
1732 if ($res !== true) {
1733 return false;
1734 }
1735 if ($this->zip->extractTo($path)) {
1736 $this->zip->close();
1737 return true;
1738 }
1739 return false;
1740 }
1741 /**
1742 * Add file/folder to archive
1743 * @param string $filename
1744 * @return bool
1745 */
1746 private function addFileOrDir($filename)
1747 {
1748 if (is_file($filename)) {
1749 return $this->zip->addFile($filename);
1750 } elseif (is_dir($filename)) {
1751 return $this->addDir($filename);
1752 }
1753 return false;
1754 }
1755 /**
1756 * Add folder recursively
1757 * @param string $path
1758 * @return bool
1759 */
1760 private function addDir($path)
1761 {
1762 if (!$this->zip->addEmptyDir($path)) {
1763 return false;
1764 }
1765 $objects = scandir($path);
1766 if (is_array($objects)) {
1767 foreach ($objects as $file) {
1768 if ($file != '.' && $file != '..') {
1769 if (is_dir($path . '/' . $file)) {
1770 if (!$this->addDir($path . '/' . $file)) {
1771 return false;
1772 }
1773 } elseif (is_file($path . '/' . $file)) {
1774 if (!$this->zip->addFile($path . '/' . $file)) {
1775 return false;
1776 }
1777 }
1778 }
1779 }
1780 return true;
1781 }
1782 return false;
1783 }
1784}
1785//--- templates functions
1786/**
1787 * Show nav block
1788 * @param string $path
1789 */
1790function fm_show_nav_path($path)
1791{
1792 global $lang;
1793 ?>
1794<div class="path main-nav">
1795
1796 <?php
1797 $path = fm_clean_path($path);
1798 $root_url = "<a href='?p='><i class='fa fa-home' aria-hidden='true' title='" . FM_ROOT_PATH . "'></i></a>";
1799 $sep = '<i class="fa fa-caret-right"></i>';
1800 if ($path != '') {
1801 $exploded = explode('/', $path);
1802 $count = count($exploded);
1803 $array = array();
1804 $parent = '';
1805 for ($i = 0; $i < $count; $i++) {
1806 $parent = trim($parent . '/' . $exploded[$i], '/');
1807 $parent_enc = urlencode($parent);
1808 $array[] = "<a href='?p={$parent_enc}'>" . fm_enc(fm_convert_win($exploded[$i])) . "</a>";
1809 }
1810 $root_url .= $sep . implode($sep, $array);
1811 }
1812 echo '<div class="break-word float-left">' . $root_url . '</div>';
1813 ?>
1814
1815 <div class="float-right">
1816 <?php if (!FM_READONLY): ?>
1817 <a title="Search" href="javascript:showSearch('<?php echo urlencode(FM_PATH) ?>')"><i class="fa fa-search"></i></a>
1818 <a title="Upload files" href="?p=<?php echo urlencode(FM_PATH) ?>&upload"><i class="fa fa-cloud-upload" aria-hidden="true"></i></a>
1819 <a title="New folder" href="#createNewItem" ><i class="fa fa-plus-square"></i></a>
1820 <?php endif; ?>
1821 <?php if (FM_USE_AUTH): ?><a title="Logout" href="?logout=1"><i class="fa fa-sign-out" aria-hidden="true"></i></a><?php endif; ?>
1822 </div>
1823</div>
1824<?php
1825}
1826/**
1827 * Show message from session
1828 */
1829function fm_show_message()
1830{
1831 if (isset($_SESSION['message'])) {
1832 $class = isset($_SESSION['status']) ? $_SESSION['status'] : 'ok';
1833 echo '<p class="message ' . $class . '">' . $_SESSION['message'] . '</p>';
1834 unset($_SESSION['message']);
1835 unset($_SESSION['status']);
1836 }
1837}
1838/**
1839 * Show page header in Login Form
1840 */
1841function fm_show_header_login()
1842{
1843 $sprites_ver = '20160315';
1844 header("Content-Type: text/html; charset=utf-8");
1845 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
1846 header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
1847 header("Pragma: no-cache");
1848 global $lang;
1849 ?>
1850<!DOCTYPE html>
1851<html>
1852<head>
1853<meta charset="utf-8">
1854<title>H3K | File Manager</title>
1855<meta name="Description" CONTENT="Author: CCP Programmers, H3K Tiny PHP File Manager">
1856<link rel="icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
1857<link rel="shortcut icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
1858<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
1859<style>
1860a img,img{border:none}.filename,td,th{white-space:nowrap}.close,.close:focus,.close:hover,.php-file-tree a,a{text-decoration:none}a,body,code,div,em,form,html,img,label,li,ol,p,pre,small,span,strong,table,td,th,tr,ul{margin:0;padding:0;vertical-align:baseline;outline:0;font-size:100%;background:0 0;border:none;text-decoration:none}p,table,ul{margin-bottom:10px}html{overflow-y:scroll}body{padding:0;font:13px/16px Tahoma,Arial,sans-serif;color:#222;background:#F7F7F7;margin:50px 30px 0}button,input,select,textarea{font-size:inherit;font-family:inherit}a{color:#296ea3}a:hover{color:#b00}img{vertical-align:middle}span{color:#777}small{font-size:11px;color:#999}ul{list-style-type:none;margin-left:0}ul li{padding:3px 0}table{border-collapse:collapse;border-spacing:0;width:100%}.file-tree-view+#main-table{width:75%!important;float:left}td,th{padding:4px 7px;text-align:left;vertical-align:top;border:1px solid #ddd;background:#fff}td.gray,th{background-color:#eee}td.gray span{color:#222}tr:hover td{background-color:#f5f5f5}tr:hover td.gray{background-color:#eee}.table{width:100%;max-width:100%;margin-bottom:1rem}.table td,.table th{padding:.55rem;vertical-align:top;border-top:1px solid #ddd}.table thead th{vertical-align:bottom;border-bottom:2px solid #eceeef}.table tbody+tbody{border-top:2px solid #eceeef}.table .table{background-color:#fff}code,pre{display:block;margin-bottom:10px;font:13px/16px Consolas,'Courier New',Courier,monospace;border:1px dashed #ccc;padding:5px;overflow:auto}.hidden,.modal{display:none}.btn,.close{font-weight:700}pre.with-hljs{padding:0}pre.with-hljs code{margin:0;border:0;overflow:visible}code.maxheight,pre.maxheight{max-height:512px}input[type=checkbox]{margin:0;padding:0}.message,.path{padding:4px 7px;border:1px solid #ddd;background-color:#fff}.fa.fa-caret-right{font-size:1.2em;margin:0 4px;vertical-align:middle;color:#ececec}.fa.fa-home{font-size:1.2em;vertical-align:bottom}#wrapper{min-width:400px;margin:0 auto}.path{margin-bottom:10px}.right{text-align:right}.center,.close,.login-form{text-align:center}.float-right{float:right}.float-left{float:left}.message.ok{border-color:green;color:green}.message.error{border-color:red;color:red}.message.alert{border-color:orange;color:orange}.btn{border:0;background:0 0;padding:0;margin:0;color:#296ea3;cursor:pointer}.btn:hover{color:#b00}.preview-img{max-width:100%;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC)}.inline-actions>a>i{font-size:1em;margin-left:5px;background:#3785c1;color:#fff;padding:3px;border-radius:3px}.preview-video{position:relative;max-width:100%;height:0;padding-bottom:62.5%;margin-bottom:10px}.preview-video video{position:absolute;width:100%;height:100%;left:0;top:0;background:#000}.compact-table{border:0;width:auto}.compact-table td,.compact-table th{width:100px;border:0;text-align:center}.compact-table tr:hover td{background-color:#fff}.filename{max-width:420px;overflow:hidden;text-overflow:ellipsis}.break-word{word-wrap:break-word;margin-left:30px}.break-word.float-left a{color:#7d7d7d}.break-word+.float-right{padding-right:30px;position:relative}.break-word+.float-right>a{color:#7d7d7d;font-size:1.2em;margin-right:4px}.modal{position:fixed;z-index:1;padding-top:100px;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:#000;background-color:rgba(0,0,0,.4)}#editor,.edit-file-actions{position:absolute;right:30px}.modal-content{background-color:#fefefe;margin:auto;padding:20px;border:1px solid #888;width:80%}.close:focus,.close:hover{color:#000;cursor:pointer}#editor{top:50px;bottom:5px;left:30px}.edit-file-actions{top:0;background:#fff;margin-top:5px}.edit-file-actions>a,.edit-file-actions>button{background:#fff;padding:5px 15px;cursor:pointer;color:#296ea3;border:1px solid #296ea3}.group-btn{background:#fff;padding:2px 6px;border:1px solid;cursor:pointer;color:#296ea3}.main-nav{position:fixed;top:0;left:0;padding:10px 30px 10px 1px;width:100%;background:#fff;color:#000;border:0;box-shadow:0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12),0 2px 4px -1px rgba(0,0,0,.2)}.login-form{width:320px;margin:0 auto;box-shadow:0 8px 10px 1px rgba(0,0,0,.14),0 3px 14px 2px rgba(0,0,0,.12),0 5px 5px -3px rgba(0,0,0,.2)}.login-form label,.path.login-form input{padding:8px;margin:10px}.footer-links{background:0 0;border:0;clear:both}select[name=lang]{border:none;position:relative;text-transform:uppercase;left:-30%;top:12px;color:silver}input[type=search]{height:30px;margin:5px;width:80%;border:1px solid #ccc}.path.login-form input[type=submit]{background-color:#4285f4;color:#fff;border:1px solid;border-radius:2px;font-weight:700;cursor:pointer}.modalDialog{position:fixed;font-family:Arial,Helvetica,sans-serif;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.8);z-index:99999;opacity:0;-webkit-transition:opacity .4s ease-in;-moz-transition:opacity .4s ease-in;transition:opacity .4s ease-in;pointer-events:none}.modalDialog:target{opacity:1;pointer-events:auto}.modalDialog>.model-wrapper{max-width:400px;position:relative;margin:10% auto;padding:15px;border-radius:2px;background:#fff}.close{float:right;background:#fff;color:#000;line-height:25px;position:absolute;right:0;top:0;width:24px;border-radius:0 5px 0 0;font-size:18px}.close:hover{background:#e4e4e4}.modalDialog p{line-height:30px}div#searchresultWrapper{max-height:320px;overflow:auto}div#searchresultWrapper li{margin:8px 0;list-style:none}li.file:before,li.folder:before{font:normal normal normal 14px/1 FontAwesome;content:"\f016";margin-right:5px}li.folder:before{content:"\f114"}i.fa.fa-folder-o{color:#eeaf4b}i.fa.fa-picture-o{color:#26b99a}i.fa.fa-file-archive-o{color:#da7d7d}.footer-links i.fa.fa-file-archive-o{color:#296ea3}i.fa.fa-css3{color:#f36fa0}i.fa.fa-file-code-o{color:#ec6630}i.fa.fa-code{color:#cc4b4c}i.fa.fa-file-text-o{color:#0096e6}i.fa.fa-html5{color:#d75e72}i.fa.fa-file-excel-o{color:#09c55d}i.fa.fa-file-powerpoint-o{color:#f6712e}.file-tree-view{width:24%;float:left;overflow:auto;border:1px solid #ddd;border-right:0;background:#fff}.file-tree-view .tree-title{background:#eee;padding:9px 2px 9px 10px;font-weight:700}.file-tree-view ul{margin-left:15px;margin-bottom:0}.file-tree-view i{padding-right:3px}.php-file-tree{font-size:100%;letter-spacing:1px;line-height:1.5;margin-left:5px!important}.php-file-tree a{color:#296ea3}.php-file-tree A:hover{color:#b00}.php-file-tree .open{font-style:italic;color:#2183ce}.php-file-tree .closed{font-style:normal}#file-tree-view::-webkit-scrollbar{width:10px;background-color:#F5F5F5}#file-tree-view::-webkit-scrollbar-track{border-radius:10px;background:rgba(0,0,0,.1);border:1px solid #ccc}#file-tree-view::-webkit-scrollbar-thumb{border-radius:10px;background:linear-gradient(left,#fff,#e4e4e4);border:1px solid #aaa}#file-tree-view::-webkit-scrollbar-thumb:hover{background:#fff}#file-tree-view::-webkit-scrollbar-thumb:active{background:linear-gradient(left,#22ADD4,#1E98BA)}
1861</style>
1862</head>
1863<body>
1864<div id="wrapper">
1865
1866<?php
1867}
1868/**
1869 * Show page footer in Login Form
1870 */
1871function fm_show_footer_login()
1872{
1873 ?>
1874</div>
1875</body>
1876</html>
1877<?php
1878}
1879/**
1880 * Show page header
1881 */
1882function fm_show_header()
1883{
1884 $sprites_ver = '20160315';
1885 header("Content-Type: text/html; charset=utf-8");
1886 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
1887 header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
1888 header("Pragma: no-cache");
1889 global $lang;
1890 ?>
1891<!DOCTYPE html>
1892<html>
1893<head>
1894<meta charset="utf-8">
1895<title>H3K | File Manager</title>
1896<meta name="Description" CONTENT="Author: CCP Programmers, H3K Tiny PHP File Manager">
1897<link rel="icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
1898<link rel="shortcut icon" href="<?php echo FM_SELF_URL ?>?img=favicon" type="image/png">
1899<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
1900<?php if (isset($_GET['view']) && FM_USE_HIGHLIGHTJS): ?>
1901<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/<?php echo FM_HIGHLIGHTJS_STYLE ?>.min.css">
1902<?php endif; ?>
1903<style>
1904a img,img{border:none}.filename,td,th{white-space:nowrap}.close,.close:focus,.close:hover,.php-file-tree a,a{text-decoration:none}a,body,code,div,em,form,html,img,label,li,ol,p,pre,small,span,strong,table,td,th,tr,ul{margin:0;padding:0;vertical-align:baseline;outline:0;font-size:100%;background:0 0;border:none;text-decoration:none}p,table,ul{margin-bottom:10px}html{overflow-y:scroll}body{padding:0;font:13px/16px Tahoma,Arial,sans-serif;color:#222;background:#F7F7F7;margin:50px 30px 0}button,input,select,textarea{font-size:inherit;font-family:inherit}a{color:#296ea3}a:hover{color:#b00}img{vertical-align:middle}span{color:#777}small{font-size:11px;color:#999}ul{list-style-type:none;margin-left:0}ul li{padding:3px 0}table{border-collapse:collapse;border-spacing:0;width:100%}.file-tree-view+#main-table{width:75%!important;float:left}td,th{padding:4px 7px;text-align:left;vertical-align:top;border:1px solid #ddd;background:#fff}td.gray,th{background-color:#eee}td.gray span{color:#222}tr:hover td{background-color:#f5f5f5}tr:hover td.gray{background-color:#eee}.table{width:100%;max-width:100%;margin-bottom:1rem}.table td,.table th{padding:.55rem;vertical-align:top;border-top:1px solid #ddd}.table thead th{vertical-align:bottom;border-bottom:2px solid #eceeef}.table tbody+tbody{border-top:2px solid #eceeef}.table .table{background-color:#fff}code,pre{display:block;margin-bottom:10px;font:13px/16px Consolas,'Courier New',Courier,monospace;border:1px dashed #ccc;padding:5px;overflow:auto}.hidden,.modal{display:none}.btn,.close{font-weight:700}pre.with-hljs{padding:0}pre.with-hljs code{margin:0;border:0;overflow:visible}code.maxheight,pre.maxheight{max-height:512px}input[type=checkbox]{margin:0;padding:0}.message,.path{padding:4px 7px;border:1px solid #ddd;background-color:#fff}.fa.fa-caret-right{font-size:1.2em;margin:0 4px;vertical-align:middle;color:#ececec}.fa.fa-home{font-size:1.2em;vertical-align:bottom}#wrapper{min-width:400px;margin:0 auto}.path{margin-bottom:10px}.right{text-align:right}.center,.close,.login-form{text-align:center}.float-right{float:right}.float-left{float:left}.message.ok{border-color:green;color:green}.message.error{border-color:red;color:red}.message.alert{border-color:orange;color:orange}.btn{border:0;background:0 0;padding:0;margin:0;color:#296ea3;cursor:pointer}.btn:hover{color:#b00}.preview-img{max-width:100%;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAKklEQVR42mL5//8/Azbw+PFjrOJMDCSCUQ3EABZc4S0rKzsaSvTTABBgAMyfCMsY4B9iAAAAAElFTkSuQmCC)}.inline-actions>a>i{font-size:1em;margin-left:5px;background:#3785c1;color:#fff;padding:3px;border-radius:3px}.preview-video{position:relative;max-width:100%;height:0;padding-bottom:62.5%;margin-bottom:10px}.preview-video video{position:absolute;width:100%;height:100%;left:0;top:0;background:#000}.compact-table{border:0;width:auto}.compact-table td,.compact-table th{width:100px;border:0;text-align:center}.compact-table tr:hover td{background-color:#fff}.filename{max-width:420px;overflow:hidden;text-overflow:ellipsis}.break-word{word-wrap:break-word;margin-left:30px}.break-word.float-left a{color:#7d7d7d}.break-word+.float-right{padding-right:30px;position:relative}.break-word+.float-right>a{color:#7d7d7d;font-size:1.2em;margin-right:4px}.modal{position:fixed;z-index:1;padding-top:100px;left:0;top:0;width:100%;height:100%;overflow:auto;background-color:#000;background-color:rgba(0,0,0,.4)}#editor,.edit-file-actions{position:absolute;right:30px}.modal-content{background-color:#fefefe;margin:auto;padding:20px;border:1px solid #888;width:80%}.close:focus,.close:hover{color:#000;cursor:pointer}#editor{top:50px;bottom:5px;left:30px}.edit-file-actions{top:0;background:#fff;margin-top:5px}.edit-file-actions>a,.edit-file-actions>button{background:#fff;padding:5px 15px;cursor:pointer;color:#296ea3;border:1px solid #296ea3}.group-btn{background:#fff;padding:2px 6px;border:1px solid;cursor:pointer;color:#296ea3}.main-nav{position:fixed;top:0;left:0;padding:10px 30px 10px 1px;width:100%;background:#fff;color:#000;border:0;box-shadow:0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12),0 2px 4px -1px rgba(0,0,0,.2)}.login-form{width:320px;margin:0 auto;box-shadow:0 8px 10px 1px rgba(0,0,0,.14),0 3px 14px 2px rgba(0,0,0,.12),0 5px 5px -3px rgba(0,0,0,.2)}.login-form label,.path.login-form input{padding:8px;margin:10px}.footer-links{background:0 0;border:0;clear:both}select[name=lang]{border:none;position:relative;text-transform:uppercase;left:-30%;top:12px;color:silver}input[type=search]{height:30px;margin:5px;width:80%;border:1px solid #ccc}.path.login-form input[type=submit]{background-color:#4285f4;color:#fff;border:1px solid;border-radius:2px;font-weight:700;cursor:pointer}.modalDialog{position:fixed;font-family:Arial,Helvetica,sans-serif;top:0;right:0;bottom:0;left:0;background:rgba(0,0,0,.8);z-index:99999;opacity:0;-webkit-transition:opacity .4s ease-in;-moz-transition:opacity .4s ease-in;transition:opacity .4s ease-in;pointer-events:none}.modalDialog:target{opacity:1;pointer-events:auto}.modalDialog>.model-wrapper{max-width:400px;position:relative;margin:10% auto;padding:15px;border-radius:2px;background:#fff}.close{float:right;background:#fff;color:#000;line-height:25px;position:absolute;right:0;top:0;width:24px;border-radius:0 5px 0 0;font-size:18px}.close:hover{background:#e4e4e4}.modalDialog p{line-height:30px}div#searchresultWrapper{max-height:320px;overflow:auto}div#searchresultWrapper li{margin:8px 0;list-style:none}li.file:before,li.folder:before{font:normal normal normal 14px/1 FontAwesome;content:"\f016";margin-right:5px}li.folder:before{content:"\f114"}i.fa.fa-folder-o{color:#eeaf4b}i.fa.fa-picture-o{color:#26b99a}i.fa.fa-file-archive-o{color:#da7d7d}.footer-links i.fa.fa-file-archive-o{color:#296ea3}i.fa.fa-css3{color:#f36fa0}i.fa.fa-file-code-o{color:#ec6630}i.fa.fa-code{color:#cc4b4c}i.fa.fa-file-text-o{color:#0096e6}i.fa.fa-html5{color:#d75e72}i.fa.fa-file-excel-o{color:#09c55d}i.fa.fa-file-powerpoint-o{color:#f6712e}.file-tree-view{width:24%;float:left;overflow:auto;border:1px solid #ddd;border-right:0;background:#fff}.file-tree-view .tree-title{background:#eee;padding:9px 2px 9px 10px;font-weight:700}.file-tree-view ul{margin-left:15px;margin-bottom:0}.file-tree-view i{padding-right:3px}.php-file-tree{font-size:100%;letter-spacing:1px;line-height:1.5;margin-left:5px!important}.php-file-tree a{color:#296ea3}.php-file-tree A:hover{color:#b00}.php-file-tree .open{font-style:italic;color:#2183ce}.php-file-tree .closed{font-style:normal}#file-tree-view::-webkit-scrollbar{width:10px;background-color:#F5F5F5}#file-tree-view::-webkit-scrollbar-track{border-radius:10px;background:rgba(0,0,0,.1);border:1px solid #ccc}#file-tree-view::-webkit-scrollbar-thumb{border-radius:10px;background:linear-gradient(left,#fff,#e4e4e4);border:1px solid #aaa}#file-tree-view::-webkit-scrollbar-thumb:hover{background:#fff}#file-tree-view::-webkit-scrollbar-thumb:active{background:linear-gradient(left,#22ADD4,#1E98BA)}
1905</style>
1906</head>
1907<body>
1908<div id="wrapper">
1909 <div id="createNewItem" class="modalDialog"><div class="model-wrapper"><a href="#close" title="Close" class="close">X</a><h2>Create New Item</h2><p>
1910 <label for="newfile">Item Type : </label><input type="radio" name="newfile" id="newfile" value="file">File <input type="radio" name="newfile" value="folder" checked> Folder<br><label for="newfilename">Item Name : </label><input type="text" name="newfilename" id="newfilename" value=""><br>
1911 <input type="submit" name="submit" class="group-btn" value="Create Now" onclick="newfolder('<?php echo fm_enc(FM_PATH) ?>');return false;"></p></div></div>
1912 <div id="searchResult" class="modalDialog"><div class="model-wrapper"><a href="#close" title="Close" class="close">X</a>
1913 <input type="search" name="search" value="" placeholder="Find a item in current folder...">
1914 <h2>Search Results</h2>
1915 <div id="searchresultWrapper"></div>
1916 </div></div>
1917<?php
1918}
1919/**
1920 * Show page footer
1921 */
1922function fm_show_footer()
1923{
1924 ?>
1925</div>
1926<script>
1927function newfolder(e){var t=document.getElementById("newfilename").value,n=document.querySelector('input[name="newfile"]:checked').value;null!==t&&""!==t&&n&&(window.location.hash="#",window.location.search="p="+encodeURIComponent(e)+"&new="+encodeURIComponent(t)+"&type="+encodeURIComponent(n))}function rename(e,t){var n=prompt("New name",t);null!==n&&""!==n&&n!=t&&(window.location.search="p="+encodeURIComponent(e)+"&ren="+encodeURIComponent(t)+"&to="+encodeURIComponent(n))}function change_checkboxes(e,t){for(var n=e.length-1;n>=0;n--)e[n].checked="boolean"==typeof t?t:!e[n].checked}function get_checkboxes(){for(var e=document.getElementsByName("file[]"),t=[],n=e.length-1;n>=0;n--)(e[n].type="checkbox")&&t.push(e[n]);return t}function select_all(){change_checkboxes(get_checkboxes(),!0)}function unselect_all(){change_checkboxes(get_checkboxes(),!1)}function invert_all(){change_checkboxes(get_checkboxes())}function mailto(e,t){var n=new XMLHttpRequest,a="path="+e+"&file="+t+"&type=mail&ajax=true";n.open("POST","",!0),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.onreadystatechange=function(){4==n.readyState&&200==n.status&&alert(n.responseText)},n.send(a)}function showSearch(e){var t=new XMLHttpRequest,n="path="+e+"&type=search&ajax=true";t.open("POST","",!0),t.setRequestHeader("Content-type","application/x-www-form-urlencoded"),t.onreadystatechange=function(){4==t.readyState&&200==t.status&&(window.searchObj=t.responseText,document.getElementById("searchresultWrapper").innerHTML="",window.location.hash="#searchResult")},t.send(n)}function getSearchResult(e,t){var n=[],a=[];return e.forEach(function(e){"folder"===e.type?(getSearchResult(e.items,t),e.name.toLowerCase().match(t)&&n.push(e)):"file"===e.type&&e.name.toLowerCase().match(t)&&a.push(e)}),{folders:n,files:a}}function checkbox_toggle(){var e=get_checkboxes();e.push(this),change_checkboxes(e)}function backup(e,t){var n=new XMLHttpRequest,a="path="+e+"&file="+t+"&type=backup&ajax=true";return n.open("POST","",!0),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.onreadystatechange=function(){4==n.readyState&&200==n.status&&alert(n.responseText)},n.send(a),!1}function edit_save(e,t){var n="ace"==t?editor.getSession().getValue():document.getElementById("normal-editor").value;if(n){var a=document.createElement("form");a.setAttribute("method","POST"),a.setAttribute("action","");var o=document.createElement("textarea");o.setAttribute("type","textarea"),o.setAttribute("name","savedata");var c=document.createTextNode(n);o.appendChild(c),a.appendChild(o),document.body.appendChild(a),a.submit()}}function init_php_file_tree(){if(document.getElementsByTagName){for(var e=document.getElementsByTagName("LI"),t=0;t<e.length;t++){var n=e[t].className;if(n.indexOf("pft-directory")>-1)for(var a=e[t].childNodes,o=0;o<a.length;o++)"A"==a[o].tagName&&(a[o].onclick=function(){for(var e=this.nextSibling;;){if(null==e)return!1;if("UL"==e.tagName){var t="none"==e.style.display;return e.style.display=t?"block":"none",this.className=t?"open":"closed",!1}e=e.nextSibling}return!1},a[o].className=n.indexOf("open")>-1?"open":"closed"),"UL"==a[o].tagName&&(a[o].style.display=n.indexOf("open")>-1?"block":"none")}return!1}}var searchEl=document.querySelector("input[type=search]"),timeout=null;searchEl.onkeyup=function(e){clearTimeout(timeout);var t=JSON.parse(window.searchObj),n=document.querySelector("input[type=search]").value;timeout=setTimeout(function(){if(n.length>=2){var e=getSearchResult(t,n),a="",o="";e.folders.forEach(function(e){a+='<li class="'+e.type+'"><a href="?p='+e.path+'">'+e.name+"</a></li>"}),e.files.forEach(function(e){o+='<li class="'+e.type+'"><a href="?p='+e.path+"&view="+e.name+'">'+e.name+"</a></li>"}),document.getElementById("searchresultWrapper").innerHTML='<div class="model-wrapper">'+a+o+"</div>"}},500)},window.onload=init_php_file_tree;if(document.getElementById("file-tree-view")){var tableViewHt=document.getElementById("main-table").offsetHeight-2;document.getElementById("file-tree-view").setAttribute("style","height:"+tableViewHt+"px")};
1928</script>
1929<?php if (isset($_GET['view']) && FM_USE_HIGHLIGHTJS): ?>
1930<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
1931<script>hljs.initHighlightingOnLoad();</script>
1932<?php endif; ?>
1933<?php if (isset($_GET['edit']) && isset($_GET['env']) && FM_EDIT_FILE): ?>
1934<script src="//cdnjs.cloudflare.com/ajax/libs/ace/1.2.9/ace.js"></script>
1935<script>var editor = ace.edit("editor");editor.getSession().setMode("ace/mode/javascript");</script>
1936<?php endif; ?>
1937</body>
1938</html>
1939<?php
1940}
1941/**
1942 * Show image
1943 * @param string $img
1944 */
1945function fm_show_image($img)
1946{
1947 $modified_time = gmdate('D, d M Y 00:00:00') . ' GMT';
1948 $expires_time = gmdate('D, d M Y 00:00:00', strtotime('+1 day')) . ' GMT';
1949 $img = trim($img);
1950 $images = fm_get_images();
1951 $image = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42mL4//8/A0CAAQAI/AL+26JNFgAAAABJRU5ErkJggg==';
1952 if (isset($images[$img])) {
1953 $image = $images[$img];
1954 }
1955 $image = base64_decode($image);
1956 if (function_exists('mb_strlen')) {
1957 $size = mb_strlen($image, '8bit');
1958 } else {
1959 $size = strlen($image);
1960 }
1961 if (function_exists('header_remove')) {
1962 header_remove('Cache-Control');
1963 header_remove('Pragma');
1964 } else {
1965 header('Cache-Control:');
1966 header('Pragma:');
1967 }
1968 header('Last-Modified: ' . $modified_time, true, 200);
1969 header('Expires: ' . $expires_time);
1970 header('Content-Length: ' . $size);
1971 header('Content-Type: image/png');
1972 echo $image;
1973 exit;
1974}
1975/**
1976 * Get base64-encoded images
1977 * @return array
1978 */
1979function fm_get_images()
1980{
1981 return array(
1982 'favicon' => 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
1983bWFnZVJlYWR5ccllPAAAAZVJREFUeNqkk79Lw0AUx1+uidTQim4Waxfpnl1BcHMR6uLkIF0cpYOI
1984f4KbOFcRwbGTc0HQSVQQXCqlFIXgFkhIyvWS870LaaPYH9CDy8vdfb+fey930aSUMEvT6VHVzw8x
1985rKUX3N3Hj/8M+cZ6GcOtBPl6KY5iAA7KJzfVWrfbhUKhALZtQ6myDf1+X5nsuzjLUmUOnpa+v5r1
1986Z4ZDDfsLiwER45xDEATgOI6KntfDd091GidzC8vZ4vH1QQ09+4MSMAMWRREKPMhmsyr6voYmrnb2
1987PKEizdEabUaeFCDKCCHAdV0wTVNFznMgpVqGlZ2cipzHGtKSZwCIZJgJwxB38KHT6Sjx21V75Jcn
1988LXmGAKTRpGVZUx2dAqQzSEqw9kqwuGqONTufPrw37D8lQFxCvjgPXIixANLEGfwuQacMOC4kZz+q
1989GdhJS550BjpRCdCbAJCMJRkMASEIg+4Bxz4JwAwDSEueAYDLIM+QrOk6GHiRxjXSkJY8KUCvdXZ6
1990kbuvNx+mOcbN9taGBlpLAWf9nX8EGADoCfqkKWV/cgAAAABJRU5ErkJggg==',
1991 'sprites' => 'iVBORw0KGgoAAAANSUhEUgAAAYAAAAAgCAMAAAAscl/XAAAC/VBMVEUAAABUfn4KKipIcXFSeXsx
1992VlZSUlNAZ2c4Xl4lSUkRDg7w8O/d3d3LhwAWFhYXODgMLCx8fHw9PT2TtdOOAACMXgE8lt+dmpq+
1993fgABS3RUpN+VUycuh9IgeMJUe4C5dUI6meKkAQEKCgoMWp5qtusJmxSUPgKudAAXCghQMieMAgIU
1994abNSUlJLe70VAQEsh85oaGjBEhIBOGxfAoyUbUQAkw8gui4LBgbOiFPHx8cZX6PMS1OqFha/MjIK
1995VKFGBABSAXovGAkrg86xAgIoS5Y7c6Nf7W1Hz1NmAQB3Hgx8fHyiTAAwp+eTz/JdDAJ0JwAAlxCQ
1996UAAvmeRiYp6ysrmIAABJr/ErmiKmcsATpRyfEBAOdQgOXahyAAAecr1JCwHMiABgfK92doQGBgZG
1997AGkqKiw0ldYuTHCYsF86gB05UlJmQSlra2tVWED////8/f3t9fX5/Pzi8/Px9vb2+/v0+fnn8vLf
19987OzZ6enV5+eTpKTo6Oj6/v765Z/U5eX4+Pjx+Pjv0ojWBASxw8O8vL52dnfR19CvAADR3PHr6+vi
19994uPDx8v/866nZDO7iNT335jtzIL+7aj86aTIztXDw8X13JOlpKJoaHDJAACltratrq3lAgKfAADb
20004vb76N2au9by2I9gYGVIRkhNTE90wfXq2sh8gL8QMZ3pyn27AADr+uu1traNiIh2olTTshifodQ4
2001ZM663PH97+YeRq2GqmRjmkGjnEDnfjLVVg6W4f7s6/p/0fr98+5UVF6wz+SjxNsmVb5RUVWMrc7d
2002zrrIpWI8PD3pkwhCltZFYbNZja82wPv05NPRdXzhvna4uFdIiibPegGQXankxyxe0P7PnOhTkDGA
2003gBrbhgR9fX9bW1u8nRFamcgvVrACJIvlXV06nvtdgON4mdn3og7AagBTufkucO7snJz4b28XEhIT
2004sflynsLEvIk55kr866aewo2YuYDrnFffOTk6Li6hgAn3y8XkusCHZQbt0NP571lqRDZyMw96lZXE
2005s6qcrMmJaTmVdRW2AAAAbnRSTlMAZodsJHZocHN7hP77gnaCZWdx/ki+RfqOd/7+zc9N/szMZlf8
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
2075RK5CYII=',
2076 );
2077}
2078?>