Password Required

'); } } else { echo ' Access Denied

Password Required

'; exit; } } } // Handle file content retrieval for editing if (isset($_GET['action']) && $_GET['action'] === 'get_file_content' && isset($_GET['file'])) { $filePath = realpath($_GET['dir'] . '/' . $_GET['file']); if ($filePath && is_file($filePath)) { header('Content-Type: text/plain'); echo file_get_contents($filePath); exit; } else { http_response_code(404); echo "File not found."; exit; } } // Handle current directory $currentDir = isset($_GET['dir']) ? realpath($_GET['dir']) : __DIR__; if (!$currentDir) { $currentDir = __DIR__; } // File operations if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Create folder if (isset($_POST['create_folder'])) { $folderName = sanitizeFileName($_POST['folder_name']); $newFolderPath = $currentDir . '/' . $folderName; if (!is_dir($newFolderPath)) { mkdir($newFolderPath, 0755); $message = "Folder created successfully."; } else { $message = "Folder already exists."; } } // Create file if (isset($_POST['create_file'])) { $fileName = sanitizeFileName($_POST['file_name']); $fileContent = $_POST['file_content']; $newFilePath = $currentDir . '/' . $fileName; file_put_contents($newFilePath, $fileContent); $message = "File created successfully."; } // Upload file if (isset($_FILES['upload_file'])) { $uploadedFile = $_FILES['upload_file']; $destination = $currentDir . '/' . sanitizeFileName($uploadedFile['name']); if (move_uploaded_file($uploadedFile['tmp_name'], $destination)) { $message = "File uploaded successfully."; } else { $message = "Error uploading file."; } } // Rename item if (isset($_POST['rename_item'])) { $oldName = sanitizeFileName($_POST['old_name']); $newName = sanitizeFileName($_POST['new_name']); if (rename($currentDir . '/' . $oldName, $currentDir . '/' . $newName)) { $message = "Item renamed successfully."; } else { $messageFi = "Error renaming item."; } } // Delete item if (isset($_POST['delete_item'])) { $itemName = sanitizeFileName($_POST['item_name']); $itemPath = $currentDir . '/' . $itemName; if (is_dir($itemPath)) { rmdir($itemPath); $message = "Folder deleted successfully."; } elseif (is_file($itemPath)) { unlink($itemPath); $message = "File deleted successfully."; } else { $message = "Item not found."; } } // Unzip file if (isset($_POST['unzip_file'])) { $zipFile = sanitizeFileName($_POST['zip_file']); $zip = new ZipArchive; if ($zip->open($currentDir . '/' . $zipFile) === TRUE) { $zip->extractTo($currentDir); $zip->close(); $message = "ZIP file extracted successfully."; } else { $message = "Error extracting ZIP file."; } } // Fetch remote file if ($remoteFetchAllowed && isset($_POST['fetch_remote_file'])) { $remoteUrl = filter_var($_POST['remote_url'], FILTER_VALIDATE_URL); if ($remoteUrl) { $fileName = sanitizeFileName(basename($remoteUrl)); $localPath = $currentDir . '/' . $fileName; if (file_put_contents($localPath, file_get_contents($remoteUrl))) { $message = "File downloaded successfully."; } else { $message = "Error downloading file."; } } else { $message = "Invalid URL."; } } // Edit file if (isset($_POST['edit_file'])) { $fileName = sanitizeFileName($_POST['file_name']); $fileContent = $_POST['file_content']; $filePath = $currentDir . '/' . $fileName; if (file_put_contents($filePath, $fileContent) !== false) { $message = "File edited successfully."; } else { $message = "Error editing file."; } } } // List directory contents $items = scandir($currentDir); $directories = []; $files = []; foreach ($items as $item) { if ($item === '.') continue; // Skip current directory $itemPath = $currentDir . '/' . $item; if (is_dir($itemPath)) { $directories[] = $item; } else { $files[] = $item; } } sort($directories); sort($files); // Helper functions function sanitizeFileName($filename) { return preg_replace('/[^a-zA-Z0-9._-]/', '', $filename); } function formatFileSize($bytes) { if ($bytes >= 1073741824) return number_format($bytes / 1073741824, 2) . ' GB'; if ($bytes >= 1048576) return number_format($bytes / 1048576, 2) . ' MB'; if ($bytes >= 1024) return number_format($bytes / 1024, 2) . ' KB'; return $bytes . ' bytes'; } function generateBreadcrumbs($path) { $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path)); $breadcrumbs = []; $cumulativePath = ''; // Add root $breadcrumbs[] = 'Root'; // Build breadcrumbs foreach ($parts as $part) { $cumulativePath .= DIRECTORY_SEPARATOR . $part; if (realpath($cumulativePath)) { $breadcrumbs[] = '' . htmlspecialchars($part) . ''; } } return implode(' / ', $breadcrumbs); } ?> PHP File Manager

PHP File Manager

Create Folder

Upload File

Fetch Remote File

Name Size Writable Last Modified Actions
.. (Parent Directory) - - -
-