Current Path: $currentPath

"; // 确保路径合法,防止路径遍历攻击 $basePath = realpath($basePath); // 确保 basePath 是绝对路径 if (strpos($currentPath, $basePath) !== 0) { die("Invalid directory."); } // 列出当前目录下的文件 if (isset($_GET['list'])) { $files = scandir($currentPath); echo "

Files in '$currentPath'

"; echo ""; } // 查看文件内容 if (isset($_GET['view'])) { $filePath = $_GET['path']; if (file_exists($filePath)) { echo "

Content of '$filePath'

"; echo "
" . htmlspecialchars(file_get_contents($filePath)) . "
"; } else { echo "File does not exist."; } } // 编辑文件内容 if (isset($_GET['edit'])) { $filePath = $_GET['path']; if (file_exists($filePath)) { $content = file_get_contents($filePath); echo "

Edit file: '$filePath'

"; echo "

"; } else { echo "File does not exist."; } } // 保存编辑的文件 if (isset($_POST['save'])) { $filePath = $_POST['file']; $content = $_POST['content']; if (file_put_contents($filePath, $content) !== false) { echo "File '$filePath' saved successfully."; } else { echo "Failed to save file."; } } // 新建文件功能 if (isset($_POST['create'])) { $newFileName = $_POST['filename']; $newFileContent = $_POST['filecontent']; $newFilePath = $currentPath . DIRECTORY_SEPARATOR . $newFileName; if (file_put_contents($newFilePath, $newFileContent) !== false) { echo "File '$newFileName' created successfully."; } else { echo "Failed to create file."; } } ?>

Create a new file