body{font-family:Arial;background:#222;color:#fff;} input,button{padding:8px;width:100%}
"; exit; } /* --------------------------- BASIC CONFIG --------------------------- */ $root = __DIR__; $req = isset($_GET['path']) ? $_GET['path'] : ""; // tidak trim slash lagi $req = trim($req, "/"); // pastikan tanpa leading/trailing slash $path = realpath($root . ($req ? "/" . $req : "")); if (!$path || strpos($path, $root) !== 0 || !is_dir($path)) { die("Invalid path"); } function h($s){ return htmlspecialchars($s); } function list_dir($d){ return array_diff(scandir($d), ['.','..']); } /* --------------------------- FILE ACTIONS --------------------------- */ # Create folder if (isset($_POST['newfolder']) && $_POST['newfolder']) { mkdir($path."/".$_POST['newfolder']); } # Create empty file if (isset($_POST['newfile']) && $_POST['newfile']) { file_put_contents($path."/".$_POST['newfile'], ""); } # Upload file if (!empty($_FILES['upload']['name'][0])) { // support multiple jika perlu foreach($_FILES['upload']['tmp_name'] as $k => $tmp) { if ($_FILES['upload']['error'][$k] == 0) { move_uploaded_file($tmp, $path."/".$_FILES['upload']['name'][$k]); } } } # Delete file/folder if (isset($_GET['delete']) && $_GET['delete']) { $target = $path."/".$_GET['delete']; if (is_dir($target)) { // rmdir hanya untuk empty dir, untuk recursive bisa tambah function rmdir($target); } elseif (is_file($target)) { unlink($target); } header("Location: ?path=".urlencode($req)); exit; } # Rename if (isset($_POST['rename_old']) && isset($_POST['rename_new']) && $_POST['rename_new']) { rename($path."/".$_POST['rename_old'], $path."/".$_POST['rename_new']); } # Save edited file if (isset($_POST['savefile']) && isset($_GET['edit'])) { file_put_contents($path."/".$_GET['edit'], $_POST['savefile']); header("Location: ?path=".urlencode($req)); exit; } # Download if (isset($_GET['download'])) { $file = $path."/".$_GET['download']; if (is_file($file)) { header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=".basename($file)); readfile($file); exit; } } /* --------------------------- EDIT FILE VIEW --------------------------- */ if (isset($_GET['edit'])) { $file = $path."/".$_GET['edit']; if (is_file($file)) { $content = file_get_contents($file); echo "| Name | Actions |
|---|---|
| ".h($item)." | "; if (is_dir($full)) { echo "Open | "; } else { echo "Edit | "; echo "Download | "; } echo " | "; echo "Delete"; echo " |