first commit
This commit is contained in:
10
admin/_log.php
Normal file
10
admin/_log.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// 在每次数据库修改操作后记录
|
||||
$log = sprintf(
|
||||
"[%s] %s 操作:%s \n",
|
||||
date('Y-m-d H:i:s'),
|
||||
$_SESSION['username'],
|
||||
json_encode($_POST)
|
||||
);
|
||||
file_put_contents(__DIR__.'/../logs/admin.log', $log, FILE_APPEND);
|
||||
?>
|
||||
73
admin/admin.php
Normal file
73
admin/admin.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
require_once __DIR__.'/../includes/auth.php';
|
||||
requireLogin();
|
||||
|
||||
// 处理表单提交
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
require_once __DIR__.'/../includes/db.php';
|
||||
|
||||
$urls = explode("\n", $_POST['urls']);
|
||||
$resolution = $_POST['resolution'];
|
||||
$category = $_POST['category'];
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO images (url, resolution, category) VALUES (?, ?, ?)");
|
||||
|
||||
$success = 0;
|
||||
foreach ($urls as $url) {
|
||||
$url = trim($url);
|
||||
if (filter_var($url, FILTER_VALIDATE_URL)) {
|
||||
try {
|
||||
$stmt->execute([$url, $resolution, $category]);
|
||||
$success++;
|
||||
} catch (PDOException $e) {}
|
||||
}
|
||||
}
|
||||
$message = "成功添加 {$success} 条记录";
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>管理后台</title>
|
||||
<link rel="stylesheet" href="../assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="admin-container">
|
||||
<header>
|
||||
<h1>欢迎回来,<?= htmlspecialchars($_SESSION['username']) ?></h1>
|
||||
<a href="logout.php" class="logout-btn">退出登录</a>
|
||||
</header>
|
||||
|
||||
<?php if (isset($message)): ?>
|
||||
<div class="success-msg"><?= $message ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-wrapper">
|
||||
<form method="POST">
|
||||
<div class="form-row">
|
||||
<select name="resolution" required>
|
||||
<option value="UHD">UHD</option>
|
||||
<option value="4K">4K</option>
|
||||
<option value="HD">HD</option>
|
||||
</select>
|
||||
|
||||
<select name="category" required>
|
||||
<option value="美女">美女</option>
|
||||
<option value="风景">风景</option>
|
||||
<option value="动物">动物</option>
|
||||
<option value="游戏">游戏</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<textarea name="urls"
|
||||
placeholder="请输入图片URL,每行一个"
|
||||
rows="10"
|
||||
required></textarea>
|
||||
|
||||
<button type="submit">提交数据</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
81
admin/categories.php
Normal file
81
admin/categories.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
require_once __DIR__.'/../includes/auth.php';
|
||||
requireLogin();
|
||||
|
||||
// 处理表单提交
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
require_once __DIR__.'/../includes/db.php';
|
||||
|
||||
$action = $_POST['action'] ?? '';
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
|
||||
try {
|
||||
if ($action === 'add') {
|
||||
$stmt = $pdo->prepare("INSERT INTO categories (name) VALUES (?)");
|
||||
$stmt->execute([$name]);
|
||||
$msg = "分类添加成功";
|
||||
} elseif ($action === 'delete') {
|
||||
$stmt = $pdo->prepare("DELETE FROM categories WHERE id = ?");
|
||||
$stmt->execute([$_POST['id']]);
|
||||
$msg = "分类删除成功";
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
$error = "操作失败:".$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取现有分类
|
||||
$categories = $pdo->query("SELECT * FROM categories ORDER BY name")->fetchAll();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>分类管理</title>
|
||||
<link rel="stylesheet" href="../assets/css/admin.css">
|
||||
</head>
|
||||
<body>
|
||||
<?php include '_sidebar.php'; ?>
|
||||
|
||||
<main class="content">
|
||||
<h2>分类管理</h2>
|
||||
|
||||
<!-- 新增分类表单 -->
|
||||
<div class="card">
|
||||
<form method="POST">
|
||||
<input type="text" name="name" placeholder="新分类名称" required>
|
||||
<input type="hidden" name="action" value="add">
|
||||
<button type="submit">添加分类</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 分类列表 -->
|
||||
<div class="card">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>分类名称</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($categories as $cat): ?>
|
||||
<tr>
|
||||
<td><?= $cat['id'] ?></td>
|
||||
<td><?= htmlspecialchars($cat['name']) ?></td>
|
||||
<td>
|
||||
<form method="POST"
|
||||
onsubmit="return confirm('确认删除该分类?')">
|
||||
<input type="hidden" name="action" value="delete">
|
||||
<input type="hidden" name="id" value="<?= $cat['id'] ?>">
|
||||
<button type="submit" class="btn-danger">删除</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
9
admin/index.php
Normal file
9
admin/index.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
require_once __DIR__.'/../includes/auth.php';
|
||||
|
||||
if (isLoggedIn()) {
|
||||
header("Location: admin.php");
|
||||
} else {
|
||||
header("Location: login.php");
|
||||
}
|
||||
exit;
|
||||
49
admin/login.php
Normal file
49
admin/login.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
require_once __DIR__.'/../includes/auth.php';
|
||||
|
||||
if (isLoggedIn()) {
|
||||
header("Location: admin.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$error = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = $_POST['username'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (login($username, $password)) {
|
||||
header("Location: admin.php");
|
||||
exit;
|
||||
} else {
|
||||
$error = "用户名或密码错误";
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>后台登录</title>
|
||||
<link rel="stylesheet" href="../assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="login-container">
|
||||
<div class="login-box">
|
||||
<h2>图片管理系统</h2>
|
||||
<?php if ($error): ?>
|
||||
<div class="error-msg"><?= $error ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST">
|
||||
<div class="form-group">
|
||||
<input type="text" name="username" placeholder="用户名" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" name="password" placeholder="密码" required>
|
||||
</div>
|
||||
<button type="submit">立即登录</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
7
admin/logout.php
Normal file
7
admin/logout.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
require_once __DIR__.'/../includes/auth.php';
|
||||
|
||||
session_unset();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
Reference in New Issue
Block a user