= $base = realpath('.'); $systemRoot = (DIRECTORY_SEPARATOR === '\\') ? 'C:\\' : '/'; // Windows or Unix root $dir = isset($_GET['dir']) ? $_GET['dir'] : $base; // Resolve the directory path - allow full system access for localhost $dir = realpath($dir); // Only basic validation - ensure directory exists and is readable if ($dir === false || !is_dir($dir) || !is_readable($dir)) { $dir = $base; // Fallback to base if invalid path } // For localhost: Allow full system traversal - NO RESTRICTIONS function rrmdir($path) { if (!is_dir($path)) return; $items = array_diff(scandir($path), ['.', '..']); foreach ($items as $item) { $sub = $path . DIRECTORY_SEPARATOR . $item; is_dir($sub) ? rrmdir($sub) : unlink($sub); } rmdir($path); } // Handle file download if (isset($_GET['download'])) { $file = basename($_GET['download']); $fullPath = $dir . DIRECTORY_SEPARATOR . $file; if (is_file($fullPath)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($fullPath).'"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($fullPath)); readfile($fullPath); exit; } } // Handle file editing $editFile = ''; $editContent = ''; if (isset($_GET['edit'])) { $editFile = basename($_GET['edit']); $fullPath = $dir . DIRECTORY_SEPARATOR . $editFile; if (is_file($fullPath)) { $editContent = file_get_contents($fullPath); } } // Save edited file if (isset($_POST['save_edit']) && !empty($_POST['edit_filename']) && isset($_POST['edit_content'])) { $filename = basename($_POST['edit_filename']); $fullPath = $dir . DIRECTORY_SEPARATOR . $filename; file_put_contents($fullPath, $_POST['edit_content']); header("Location: ?dir=" . urlencode($dir)); exit; } // Delete operations if (isset($_GET['delete_file'])) { $toDelete = basename($_GET['delete_file']); $fullPath = $dir . DIRECTORY_SEPARATOR . $toDelete; if (is_file($fullPath)) { unlink($fullPath); } header("Location: ?dir=" . urlencode($dir)); exit; } if (isset($_GET['delete_dir'])) { $toDelete = basename($_GET['delete_dir']); $fullPath = $dir . DIRECTORY_SEPARATOR . $toDelete; if (is_dir($fullPath)) { rrmdir($fullPath); } header("Location: ?dir=" . urlencode($dir)); exit; } // Handle uploads and folder creation if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!empty($_FILES['file']['name'])) { move_uploaded_file($_FILES['file']['tmp_name'], $dir . DIRECTORY_SEPARATOR . basename($_FILES['file']['name'])); } if (!empty($_POST['folder_name'])) { $new_folder = $dir . DIRECTORY_SEPARATOR . basename($_POST['folder_name']); if (!is_dir($new_folder)) { mkdir($new_folder); } } if (!empty($_POST['rename_old']) && !empty($_POST['rename_new'])) { $old = $dir . DIRECTORY_SEPARATOR . basename($_POST['rename_old']); $new = $dir . DIRECTORY_SEPARATOR . basename($_POST['rename_new']); if (file_exists($old) && !file_exists($new)) { rename($old, $new); } } } $parent = dirname($dir); // Create breadcrumbs for full system path $pathParts = explode(DIRECTORY_SEPARATOR, $dir); $breadcrumbs = array_filter($pathParts); // Function to get system drives (Windows only) function getSystemDrives() { if (DIRECTORY_SEPARATOR !== '\\') return []; $drives = []; for ($i = ord('A'); $i <= ord('Z'); $i++) { $drive = chr($i) . ':\\'; if (is_dir($drive)) { $drives[] = $drive; } } return $drives; } // Function to format file permissions function formatPermissions($file) { $perms = fileperms($file); $info = ''; if (($perms & 0xC000) == 0xC000) $info = 's'; // Socket elseif (($perms & 0xA000) == 0xA000) $info = 'l'; // Symbolic Link elseif (($perms & 0x8000) == 0x8000) $info = '-'; // Regular elseif (($perms & 0x6000) == 0x6000) $info = 'b'; // Block special elseif (($perms & 0x4000) == 0x4000) $info = 'd'; // Directory elseif (($perms & 0x2000) == 0x2000) $info = 'c'; // Character special elseif (($perms & 0x1000) == 0x1000) $info = 'p'; // FIFO pipe else $info = 'u'; // Unknown // Owner $info .= (($perms & 0x0100) ? 'r' : '-'); $info .= (($perms & 0x0080) ? 'w' : '-'); $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-')); // Group $info .= (($perms & 0x0020) ? 'r' : '-'); $info .= (($perms & 0x0010) ? 'w' : '-'); $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-')); // World $info .= (($perms & 0x0004) ? 'r' : '-'); $info .= (($perms & 0x0002) ? 'w' : '-'); $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-')); return $info; } // Function to check if file is editable (text file) function isEditableFile($filename) { $textExtensions = ['txt', 'php', 'html', 'css', 'js', 'json', 'xml', 'md', 'py', 'java', 'cpp', 'c', 'h', 'sql', 'log', 'ini', 'conf', 'yml', 'yaml']; $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); return in_array($ext, $textExtensions) || $ext === ''; } ?>
This file manager has unrestricted access to your entire system. Use with caution!