代码拉取完成,页面将自动刷新
<?php
// 指定目录
$directory = '/www/wwwroot/theTestFolder'; // 替换为你的目录
$notesFile = 'notes.json';
$notes = file_exists($notesFile) ? json_decode(file_get_contents($notesFile), true) : [];
// 递归函数:展示目录和文件
function displayDirectory($dir, $notes) {
$files = scandir($dir);
$directories = [];
$regularFiles = [];
// 将目录和文件分开
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
if (is_dir($dir . '/' . $file)) {
$directories[] = $file;
} else {
$regularFiles[] = $file;
}
}
}
// 按字母顺序排序
natcasesort($directories);
natcasesort($regularFiles);
echo '<ul>';
// 先展示目录
foreach ($directories as $directory) {
$filePath = $dir . '/' . $directory;
echo "<li class='item'>";
echo "<div class='directory-info'>";
echo "<span class='toggle'>[+]</span> <img src='folder-icon.png' alt='Folder' class='icon'> <strong class='folder-name'>$directory</strong>";
?>
<div class="note-container">
<form class="note-form" data-path="<?php echo htmlspecialchars($filePath); ?>">
<textarea rows="1" cols="30" class="note-input"><?php echo isset($notes[$filePath]) ? htmlspecialchars($notes[$filePath]) : ''; ?></textarea>
</form>
</div>
<?php
echo '</div>';
displayDirectory($filePath, $notes);
echo '</li>';
}
// 再展示文件
foreach ($regularFiles as $file) {
$filePath = $dir . '/' . $file;
echo "<li class='item'>";
echo "<div class='file-info'>";
echo "<img src='file-icon.png' alt='File' class='icon'> <span class='filename'>$file</span>";
?>
<div class="note-container">
<form class="note-form" data-path="<?php echo htmlspecialchars($filePath); ?>">
<textarea rows="1" cols="30" class="note-input"><?php echo isset($notes[$filePath]) ? htmlspecialchars($notes[$filePath]) : ''; ?></textarea>
</form>
</div>
<?php
echo '</div>';
echo '</li>';
}
echo '</ul>';
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FileRemark</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>theTestFolder</h1>
<?php displayDirectory($directory, $notes); ?>
<script src="script.js"></script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。