session_start();if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit();}$dir = isset($_GET['path']) ? $_GET['path'] : './';if (strpos($dir, '..') !== false) { die("Akses tidak diizinkan.");}// Tangani permintaan unggah fileif ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['fileToUpload'])) { $target_file = $dir . basename($_FILES['fileToUpload']['name']); $uploadOk = 1; $message = ''; $status = 'danger'; // Default status to danger if (file_exists($target_file)) { $message = "Maaf, file sudah ada."; $uploadOk = 0; } if ($_FILES['fileToUpload']['size'] > 5000000) { $message = "Maaf, ukuran file terlalu besar."; $uploadOk = 0; } if ($uploadOk == 0) { $message = "Maaf, file Anda tidak terunggah. " . $message; } else { if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) { $message = "File " . htmlspecialchars(basename($_FILES['fileToUpload']['name'])) . " berhasil diunggah."; $status = 'success'; // Set status to success } else { $message = "Maaf, terjadi kesalahan saat mengunggah file."; } } header("Location: " . basename($_SERVER['PHP_SELF']) . "?path=" . urlencode($dir) . "&alert_message=" . urlencode($message) . "&alert_status=" . urlencode($status)); exit;}// Tangani permintaan ganti namaif (isset($_POST['rename_old_name']) && isset($_POST['rename_new_name'])) { $old_name = basename($_POST['rename_old_name']); $new_name = basename($_POST['rename_new_name']); $status = 'danger'; if (file_exists($dir . $old_name)) { if (rename($dir . $old_name, $dir . $new_name)) { $message = "Berhasil mengganti nama " . htmlspecialchars($old_name) . " menjadi " . htmlspecialchars($new_name) . "."; $status = 'success'; } else { $message = "Gagal mengganti nama."; } } else { $message = "File tidak ditemukan."; } header("Location: " . basename($_SERVER['PHP_SELF']) . "?path=" . urlencode($dir) . "&alert_message=" . urlencode($message) . "&alert_status=" . urlencode($status)); exit;}// Tangani permintaan hapusif (isset($_GET['delete'])) { $item_name = basename($_GET['delete']); $item_path = $dir . $item_name; $status = 'danger'; if (file_exists($item_path)) { if (is_file($item_path)) { unlink($item_path); $message = "File " . htmlspecialchars($item_name) . " berhasil dihapus."; $status = 'success'; } elseif (is_dir($item_path)) { function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (is_dir($dir . "/" . $object) && !is_link($dir . "/" . $object)) { rrmdir($dir . "/" . $object); } else { unlink($dir . "/" . $object); } } } rmdir($dir); } } rrmdir($item_path); $message = "Folder " . htmlspecialchars($item_name) . " berhasil dihapus."; $status = 'success'; } } else { $message = "Item tidak ditemukan."; } header('Location: ' . basename($_SERVER['PHP_SELF']) . '?path=' . urlencode($dir) . "&alert_message=" . urlencode($message) . "&alert_status=" . urlencode($status)); exit;}// Tangani permintaan unduhif (isset($_GET['download'])) { $file_name = basename($_GET['download']); $file_to_download = $dir . $file_name; if (file_exists($file_to_download) && is_file($file_to_download)) { header('Content-Type: ' . mime_content_type($file_to_download)); header('Content-Disposition: attachment; filename="' . basename($file_to_download) . '"'); readfile($file_to_download); exit; }}$files = array_diff(scandir($dir), array('..'));<!DOCTYPE html><html lang="id">
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">Manajer File Sederhana <title>Manajer File Sederhana</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css"> <style> body { /* Gunakan gambar sebagai latar belakang */ background-image: url('https://cdn.dribbble.com/userupload/27435641/file/original-87e3cd7b0f8a9157fe2b2f10421253cb.gif'); background-size: cover; background-repeat: no-repeat; background-attachment: fixed; /* Menjadikan gambar latar belakang tetap (tidak ikut di-scroll) */ background-position: center; color: #ffffff; /* Mengubah warna teks default menjadi putih */ display: flex; flex-direction: column; min-height: 100vh;} .container { max-width: 900px; } .icon { width: 1.2rem; }a { text-decoration: none; color: whitesmoke; box-shadow: 0 1px black; border-radius: 10px; background: rgba(255, 255, 255, 0.08); padding: 4px; text-shadow: 0 1px black; } a:hover { text-decoration: none; color: #c4c4c4; box-shadow: 0 1px whitesmoke; border-radius: 10px; background: #2d2d2d88; padding: 4px; text-shadow: 0 1px black; } .gelas { /* Gaya Glassmorphism */ background: rgba(255, 255, 255, 0.08); /* Latar belakang transparan */ backdrop-filter: blur(10px); /* Efek buram pada latar belakang */ border: 1px solid rgba(255, 255, 255, 0.18); box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37); color: whitesmoke; /* Warna teks putih */ /* Transisi dan Efek Hover */ transition: transform 0.2s, box-shadow 0.2s; } } </style> <div class="container mt-5"><div class="d-flex justify-content-between align-items-center mb-4"> <h1 class="mb-0"><a href="index.php">Manajer File</a> <a href="logout.php" class="btn btn-danger">Logout</a></div> if (isset($_GET['alert_message']) && isset($_GET['alert_status'])) { $alert_type = $_GET['alert_status']; echo '<div id="myAlert" class="alert alert-' . $alert_type . ' alert-dismissible fade show" role="alert">'; echo htmlspecialchars($_GET['alert_message']); echo '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'; echo '</div>'; } <nav aria-label="breadcrumb"> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="file.php">Root</a></li> $path_parts = explode('/', trim($dir, './')); $current_path = ''; foreach ($path_parts as $part) { if ($part) { $current_path .= $part . '/'; echo "<li class='breadcrumb-item'><a href='file.php?path=" . urlencode($current_path) . "'>" . htmlspecialchars($part) . "</a></li>"; } } </ol> </nav> <div class="gelas card p-3 mb-4"> <h5 class="card-title">Unggah File Baru</h5> </div> <div class="table-responsive"> <table class="table table-striped table-hover"> <thead class="gelas"> <th>Nama</th> <th>Tipe</th> <th>Ukuran</th> <th>Aksi</th>
</thead> <tbody class="gelas"> if ($dir !== './') { $parent_dir = dirname($dir); if ($parent_dir === '.') $parent_dir = './'; echo ""; echo "<a href='file.php?path=" . urlencode($parent_dir) . "'><i class='fas fa-folder'></i> ..</a> | "; echo "Folder | "; echo "- | "; echo "- | "; echo "
"; } foreach ($files as $item) { if ($item !== '.' && $item !== '..') { $item_path = $dir . $item; if (is_dir($item_path)) { echo ""; echo "<a href='file.php?path=" . urlencode($item_path) . "/'><i class='fas fa-folder'></i> " . htmlspecialchars($item) . "</a> | "; echo "Folder | "; echo "- | "; echo ""; echo "<button class='btn btn-sm btn-warning me-2 rename-btn' data-old-name='" . htmlspecialchars($item) . "'>Ganti Nama</button>"; echo "<a href='file.php?delete=" . urlencode($item) . "&path=" . urlencode($dir) . "' class='btn btn-sm btn-danger' onclick='return confirm(\"Apakah Anda yakin ingin menghapus folder ini dan semua isinya?\")'>Hapus</a>"; echo " | "; echo "
"; } else { echo ""; echo "" . htmlspecialchars($item) . " | "; echo "File | "; if (is_file($item_path)) { echo "" . round(filesize($item_path) / 1024, 2) . " KB | "; } else { echo "- | "; } echo "<td class='text-nowrap'>"; echo "<a href='edit.php?file=" . urlencode($item) . "&path=" . urlencode($dir) . "' class='btn btn-sm btn-info me-2'>Edit</a>"; echo "<button class='btn btn-sm btn-warning me-2 rename-btn' data-old-name='" . htmlspecialchars($item) . "'>Ganti Nama</button>"; echo "<a href='file.php?download=" . urlencode($item) . "&path=" . urlencode($dir) . "' class='btn btn-sm btn-success me-2'>Unduh</a>"; echo "<a href='file.php?delete=" . urlencode($item) . "&path=" . urlencode($dir) . "' class='btn btn-sm btn-danger' onclick='return confirm(\"Apakah Anda yakin ingin menghapus file ini?\")'>Hapus</a>"; echo ""; echo "
"; } } } </tbody> </div> </div> <div class="modal fade" id="renameModal" tabindex="-1" aria-labelledby="renameModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> <script> document.addEventListener('DOMContentLoaded', function () { const renameModal = new bootstrap.Modal(document.getElementById('renameModal')); const renameForm = document.getElementById('renameForm'); const renameOldNameInput = document.getElementById('renameOldName'); const renameNewNameInput = document.getElementById('renameNewName'); document.querySelectorAll('.rename-btn').forEach(button => { button.addEventListener('click', function () { const oldName = this.getAttribute('data-old-name'); renameOldNameInput.value = oldName; renameNewNameInput.value = oldName; renameModal.show(); }); }); // Auto-dismiss alert var myAlert = document.getElementById('myAlert'); if (myAlert) { setTimeout(function() { var bsAlert = new bootstrap.Alert(myAlert); bsAlert.close(); }, 3000); // 3000 milliseconds = 3 seconds // Remove URL parameters after a short delay setTimeout(function() { const url = new URL(window.location.href); url.searchParams.delete('alert_message'); url.searchParams.delete('alert_status'); window.history.replaceState({}, document.title, url); }, 3500); // Slightly longer delay to allow the alert to be seen } }); </script>