Current Path: $currentPath

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

Files in '$currentPath'

"; // 使用 scandir 来列出文件 $files = scandir($currentPath); // 如果没有文件,则给出提示 if ($files === false) { echo "

Failed to open directory.

"; } else { 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($_GET['delete'])) { $filePath = $_GET['path']; if (is_dir($filePath)) { rmdir($filePath); // 删除空文件夹 } else { unlink($filePath); // 删除文件 } echo "Deleted '$filePath'."; } // 重命名文件或文件夹 if (isset($_GET['rename'])) { $filePath = $_GET['path']; echo "

Rename '$filePath'

"; echo "

"; } // 执行重命名操作 if (isset($_POST['renameFile'])) { $filePath = $_POST['file']; $newName = $_POST['newname']; $newPath = dirname($filePath) . DIRECTORY_SEPARATOR . $newName; if (rename($filePath, $newPath)) { echo "File renamed successfully."; } else { echo "Failed to rename 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."; } } // 创建新文件夹功能 if (isset($_GET['createFolder'])) { $folderPath = $_GET['path']; $newFolderName = $folderPath . DIRECTORY_SEPARATOR . "NewFolder"; if (mkdir($newFolderName)) { echo "Folder created successfully."; } else { echo "Failed to create folder."; } } ?>

Create a new file