aa $item, 'path' => $full, 'size' => is_file($full) ? @filesize($full) : 0, 'type' => is_dir($full) ? 'directory' : 'file', 'modified' => @filemtime($full) ? date('Y-m-d H:i:s', filemtime($full)) : '-' ]; } usort($files, function($a, $b) { if ($a['type'] !== $b['type']) { return ($a['type'] === 'directory') ? -1 : 1; } return strcasecmp($a['name'], $b['name']); }); return $files; } function format_size($bytes) { $bytes = (float)$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 rrmdir($dir) { if (!is_dir($dir)) return false; $items = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($items as $item) { if ($item->isDir()) { @rmdir($item->getRealPath()); } else { @unlink($item->getRealPath()); } } return @rmdir($dir); } /* Rule: - no dir param => default = public_html - ?dir= => root = domains */ if (!isset($_GET['dir'])) { $requested_dir = $default_rel; } else { $requested_dir = sanitize_relative_path($_GET['dir']); } $current_dir = safe_realpath_within( $root_anchor . DIRECTORY_SEPARATOR . $requested_dir, $root_anchor ); if ($current_dir === false) { $current_dir = $root_anchor; $requested_dir = ''; } $relative_current = trim(str_replace($root_anchor, '', $current_dir), DIRECTORY_SEPARATOR); $parent_dir = ''; if ($relative_current !== '') { $parent_dir = dirname($relative_current); if ($parent_dir === '.') $parent_dir = ''; } $is_at_root = ($relative_current === ''); $action = $_GET['action'] ?? 'list'; switch ($action) { case 'view': $file = sanitize_name($_GET['file'] ?? ''); $path = $current_dir . DIRECTORY_SEPARATOR . $file; $safe = safe_realpath_within($path, $root_anchor); if ($safe && is_file($safe)) { header('Content-Type: text/plain; charset=utf-8'); readfile($safe); exit; } flash('File not found.'); header('Location: ?dir=' . urlencode($relative_current)); exit; case 'edit': $file = sanitize_name($_GET['file'] ?? ''); $path = $current_dir . DIRECTORY_SEPARATOR . $file; $safe = safe_realpath_within($path, $root_anchor); if (!$safe || !is_file($safe)) { flash('Invalid file.'); header('Location: ?dir=' . urlencode($relative_current)); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $content = $_POST['content'] ?? ''; if (@file_put_contents($safe, $content) !== false) { flash('File saved successfully.'); } else { flash('Failed to save file.'); } header('Location: ?dir=' . urlencode($relative_current)); exit; } $content = htmlspecialchars((string)@file_get_contents($safe), ENT_QUOTES, 'UTF-8'); ?> Edit File

Edit:



Back
File Manager

File Manager

Root:
Current:

Back Back Default (public_html) Root (domains)




Name Type Size Modified Actions
No files found.
Open View Edit Download Delete