发布日期:session_start();
// 检查管理员是否登录
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header("Location: login.php"); // 如果没有登录,重定向到登录页面
exit;
}
// 获取文件名
$file = $_GET['file'];
$filePath = 'articles/' . $file;
// 检查文件是否存在
if (file_exists($filePath)) {
$content = file_get_contents($filePath);
$lines = explode("\n", $content);
$title = $lines[0]; // 文章标题
$date = $lines[1]; // 文章发布日期
$body = implode("\n", array_slice($lines, 2)); // 文章内容
} else {
echo "文章不存在。";
exit;
}
?>
<!-- 编辑文章表单 -->
<h2>编辑文章</h2>
<form method="POST" action="update_article.php?file=<?php echo basename($file); ?>">
<label for="title">文章标题:</label>
<input type="text" id="title" name="title" value="<?php echo htmlspecialchars($title); ?>" required><br><br>
<label for="content">文章内容:</label>
<textarea id="content" name="content" rows="10" required><?php echo htmlspecialchars($body); ?></textarea><br><br>
<label for="date">发布日期:</label>
<input type="date" id="date" name="date" value="<?php echo $date; ?>" required><br><br>
<button type="submit">保存更改</button>
</form>