connect_error) { // 尝试创建数据库 $tmp = new mysqli(DB_HOST, DB_USER, DB_PASS); $tmp->query("CREATE DATABASE IF NOT EXISTS `" . DB_NAME . "` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); $tmp->close(); $db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME); if ($db->connect_error) { die('

⚠️ 数据库连接失败

请检查 config 中的数据库配置是否正确。

Host: ' . DB_HOST . ' | User: ' . DB_USER . ' | DB: ' . DB_NAME . '

'); } } $db->set_charset('utf8mb4'); initDatabase($db); } catch (Exception $e) { die('数据库连接异常: ' . $e->getMessage()); } } return $db; } // 初始化数据库表 function initDatabase($db) { $tables = [ "users" => "CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, email VARCHAR(100) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, avatar VARCHAR(255) DEFAULT '', role ENUM('user','admin') DEFAULT 'user', created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "categories" => "CREATE TABLE IF NOT EXISTS categories ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50) NOT NULL, slug VARCHAR(50) NOT NULL UNIQUE, icon VARCHAR(10) DEFAULT '📁', description TEXT, sort_order INT DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "resources" => "CREATE TABLE IF NOT EXISTS resources ( id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(200) NOT NULL, slug VARCHAR(200) NOT NULL, description TEXT, category_id INT, user_id INT, file_path VARCHAR(500), file_size BIGINT DEFAULT 0, file_type VARCHAR(50), thumbnail VARCHAR(500) DEFAULT '', download_count INT DEFAULT 0, view_count INT DEFAULT 0, rating_avg DECIMAL(3,1) DEFAULT 0, rating_count INT DEFAULT 0, status ENUM('pending','approved','rejected') DEFAULT 'approved', featured TINYINT(1) DEFAULT 0, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE SET NULL, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "comments" => "CREATE TABLE IF NOT EXISTS comments ( id INT AUTO_INCREMENT PRIMARY KEY, resource_id INT NOT NULL, user_id INT, content TEXT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "ratings" => "CREATE TABLE IF NOT EXISTS ratings ( id INT AUTO_INCREMENT PRIMARY KEY, resource_id INT NOT NULL, user_id INT, rating TINYINT NOT NULL CHECK(rating BETWEEN 1 AND 5), created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY unique_rating (resource_id, user_id), FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", "downloads_log" => "CREATE TABLE IF NOT EXISTS downloads_log ( id INT AUTO_INCREMENT PRIMARY KEY, resource_id INT NOT NULL, user_id INT, ip_address VARCHAR(45), downloaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (resource_id) REFERENCES resources(id) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" ]; foreach ($tables as $name => $sql) { $db->query($sql); } // 插入默认分类 $catCheck = $db->query("SELECT COUNT(*) as cnt FROM categories"); $row = $catCheck->fetch_assoc(); if ($row['cnt'] == 0) { $defaultCats = [ ['name' => '软件工具', 'slug' => 'software', 'icon' => '💻', 'sort_order' => 1], ['name' => '文档模板', 'slug' => 'document', 'icon' => '📄', 'sort_order' => 2], ['name' => '源码素材', 'slug' => 'source', 'icon' => '📝', 'sort_order' => 3], ['name' => '影音资源', 'slug' => 'media', 'icon' => '🎬', 'sort_order' => 4], ['name' => '其他资源', 'slug' => 'other', 'icon' => '📦', 'sort_order' => 5], ]; $stmt = $db->prepare("INSERT INTO categories (name, slug, icon, sort_order) VALUES (?, ?, ?, ?)"); foreach ($defaultCats as $cat) { $stmt->bind_param("sssi", $cat['name'], $cat['slug'], $cat['icon'], $cat['sort_order']); $stmt->execute(); } $stmt->close(); } // 插入默认管理员 $userCheck = $db->query("SELECT COUNT(*) as cnt FROM users WHERE role='admin'"); $row = $userCheck->fetch_assoc(); if ($row['cnt'] == 0) { $adminPass = password_hash('admin123', PASSWORD_DEFAULT); $db->query("INSERT INTO users (username, email, password, role) VALUES ('admin', 'admin@reshub.com', '$adminPass', 'admin')"); } } // 获取数据库连接 $db = getDB(); // ==================== 路由处理 ==================== $action = $_GET['action'] ?? ''; $page = $_GET['page'] ?? 'home'; // 处理AJAX请求 if ($action === 'login_ajax') { header('Content-Type: application/json'); $identifier = trim($_POST['login_identifier'] ?? ''); $password = $_POST['password'] ?? ''; if (empty($identifier) || empty($password)) { echo json_encode(['success' => false, 'message' => '请填写所有字段']); exit; } $stmt = $db->prepare("SELECT id, username, password, role FROM users WHERE username = ? OR email = ?"); $stmt->bind_param("ss", $identifier, $identifier); $stmt->execute(); $result = $stmt->get_result(); if ($user = $result->fetch_assoc()) { if (password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['username'] = $user['username']; $_SESSION['role'] = $user['role']; echo json_encode(['success' => true]); exit; } } echo json_encode(['success' => false, 'message' => '用户名或密码错误']); exit; } if ($action === 'register_ajax') { header('Content-Type: application/json'); $username = trim($_POST['username'] ?? ''); $email = trim($_POST['email'] ?? ''); $password = $_POST['password'] ?? ''; if (empty($username) || empty($email) || empty($password)) { echo json_encode(['success' => false, 'message' => '请填写所有字段']); exit; } if (strlen($username) < 3 || strlen($username) > 20) { echo json_encode(['success' => false, 'message' => '用户名需3-20个字符']); exit; } if (strlen($password) < 6) { echo json_encode(['success' => false, 'message' => '密码至少6个字符']); exit; } // 检查重复 $check = $db->prepare("SELECT id FROM users WHERE username = ? OR email = ?"); $check->bind_param("ss", $username, $email); $check->execute(); if ($check->get_result()->num_rows > 0) { echo json_encode(['success' => false, 'message' => '用户名或邮箱已被使用']); exit; } $check->close(); $hashed = password_hash($password, PASSWORD_DEFAULT); $stmt = $db->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $username, $email, $hashed); if ($stmt->execute()) { echo json_encode(['success' => true]); } else { echo json_encode(['success' => false, 'message' => '注册失败,请重试']); } exit; } if ($action === 'logout') { session_destroy(); header('Location: index.php'); exit; } // 处理下载 if ($action === 'download' && isset($_GET['id'])) { $resourceId = intval($_GET['id']); $stmt = $db->prepare("SELECT id, title, file_path, download_count FROM resources WHERE id = ? AND status='approved'"); $stmt->bind_param("i", $resourceId); $stmt->execute(); $resource = $stmt->get_result()->fetch_assoc(); if ($resource) { // 更新下载计数 $db->query("UPDATE resources SET download_count = download_count + 1 WHERE id = $resourceId"); // 记录下载日志 $userId = $_SESSION['user_id'] ?? null; $ip = $_SERVER['REMOTE_ADDR']; $logStmt = $db->prepare("INSERT INTO downloads_log (resource_id, user_id, ip_address) VALUES (?, ?, ?)"); $logStmt->bind_param("iis", $resourceId, $userId, $ip); $logStmt->execute(); $logStmt->close(); $filePath = $resource['file_path']; if (file_exists($filePath)) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($filePath) . '"'); header('Content-Length: ' . filesize($filePath)); readfile($filePath); exit; } else { // 模拟下载(演示用途) header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $resource['title'] . '.zip"'); echo "这是模拟文件内容 - 资源ID: " . $resourceId . "\n"; echo "实际部署时请将文件存储在服务器上。\n"; exit; } } header('Location: ?page=detail&id=' . $resourceId . '&msg=notfound'); exit; } // 处理上传 if ($action === 'upload_resource' && $_SERVER['REQUEST_METHOD'] === 'POST') { if (!isset($_SESSION['user_id'])) { header('Location: ?page=upload&msg=login_required'); exit; } $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $categoryId = intval($_POST['category_id'] ?? 0); $fileType = trim($_POST['file_type'] ?? 'other'); if (empty($title) || $categoryId == 0) { header('Location: ?page=upload&msg=fill_all'); exit; } $slug = strtolower(preg_replace('/[^a-zA-Z0-9\x{4e00}-\x{9fa5}]+/u', '-', $title)); $slug = trim($slug, '-'); if (empty($slug)) $slug = 'resource-' . time(); $filePath = ''; $fileSize = 0; // 处理文件上传 if (isset($_FILES['resource_file']) && $_FILES['resource_file']['error'] === UPLOAD_ERR_OK) { $uploadDir = 'uploads/'; if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true); $fileName = time() . '_' . basename($_FILES['resource_file']['name']); $filePath = $uploadDir . $fileName; move_uploaded_file($_FILES['resource_file']['tmp_name'], $filePath); $fileSize = $_FILES['resource_file']['size']; } $userId = $_SESSION['user_id']; $stmt = $db->prepare("INSERT INTO resources (title, slug, description, category_id, user_id, file_path, file_size, file_type, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'approved')"); $stmt->bind_param("sssiisis", $title, $slug, $description, $categoryId, $userId, $filePath, $fileSize, $fileType); if ($stmt->execute()) { $newId = $db->insert_id; header('Location: ?page=detail&id=' . $newId . '&msg=uploaded'); } else { header('Location: ?page=upload&msg=error'); } exit; } // 处理评论 if ($action === 'add_comment' && $_SERVER['REQUEST_METHOD'] === 'POST') { header('Content-Type: application/json'); if (!isset($_SESSION['user_id'])) { echo json_encode(['success' => false, 'message' => '请先登录']); exit; } $resourceId = intval($_POST['resource_id'] ?? 0); $content = trim($_POST['content'] ?? ''); if (empty($content) || $resourceId == 0) { echo json_encode(['success' => false, 'message' => '请填写评论内容']); exit; } $userId = $_SESSION['user_id']; $stmt = $db->prepare("INSERT INTO comments (resource_id, user_id, content) VALUES (?, ?, ?)"); $stmt->bind_param("iis", $resourceId, $userId, $content); if ($stmt->execute()) { echo json_encode(['success' => true]); } else { echo json_encode(['success' => false, 'message' => '评论失败']); } exit; } // 处理评分 if ($action === 'add_rating' && $_SERVER['REQUEST_METHOD'] === 'POST') { header('Content-Type: application/json'); if (!isset($_SESSION['user_id'])) { echo json_encode(['success' => false, 'message' => '请先登录']); exit; } $resourceId = intval($_POST['resource_id'] ?? 0); $rating = intval($_POST['rating'] ?? 0); if ($rating < 1 || $rating > 5 || $resourceId == 0) { echo json_encode(['success' => false, 'message' => '评分无效']); exit; } $userId = $_SESSION['user_id']; // 使用REPLACE或先删除再插入 $db->query("DELETE FROM ratings WHERE resource_id = $resourceId AND user_id = $userId"); $stmt = $db->prepare("INSERT INTO ratings (resource_id, user_id, rating) VALUES (?, ?, ?)"); $stmt->bind_param("iii", $resourceId, $userId, $rating); $stmt->execute(); // 更新平均评分 $avgResult = $db->query("SELECT AVG(rating) as avg_r, COUNT(*) as cnt FROM ratings WHERE resource_id = $resourceId"); $avgRow = $avgResult->fetch_assoc(); $avgR = round($avgRow['avg_r'], 1); $cnt = $avgRow['cnt']; $db->query("UPDATE resources SET rating_avg = $avgR, rating_count = $cnt WHERE id = $resourceId"); echo json_encode(['success' => true, 'rating_avg' => $avgR, 'rating_count' => $cnt]); exit; } // 处理管理员操作 if ($action === 'admin_delete_resource' && isset($_SESSION['user_id']) && $_SESSION['role'] === 'admin') { $resId = intval($_GET['id'] ?? 0); if ($resId > 0) { $db->query("DELETE FROM resources WHERE id = $resId"); } header('Location: ?page=admin&tab=resources&msg=deleted'); exit; } if ($action === 'admin_toggle_featured' && isset($_SESSION['user_id']) && $_SESSION['role'] === 'admin') { $resId = intval($_GET['id'] ?? 0); if ($resId > 0) { $db->query("UPDATE resources SET featured = 1 - featured WHERE id = $resId"); } header('Location: ?page=admin&tab=resources&msg=toggled'); exit; } // ==================== 页面显示函数 ==================== function displayHomePage() { global $db; // 获取统计数据 $totalResources = $db->query("SELECT COUNT(*) as cnt FROM resources WHERE status='approved'")->fetch_assoc()['cnt']; $totalDownloads = $db->query("SELECT SUM(download_count) as cnt FROM resources WHERE status='approved'")->fetch_assoc()['cnt'] ?? 0; $totalUsers = $db->query("SELECT COUNT(*) as cnt FROM users")->fetch_assoc()['cnt']; $totalCategories = $db->query("SELECT COUNT(*) as cnt FROM categories")->fetch_assoc()['cnt']; // 获取分类 $categories = $db->query("SELECT c.*, COUNT(r.id) as res_count FROM categories c LEFT JOIN resources r ON c.id = r.category_id AND r.status='approved' GROUP BY c.id ORDER BY c.sort_order"); // 获取推荐资源 $featured = $db->query("SELECT r.*, c.name as cat_name, c.slug as cat_slug, u.username FROM resources r LEFT JOIN categories c ON r.category_id = c.id LEFT JOIN users u ON r.user_id = u.id WHERE r.status='approved' AND r.featured = 1 ORDER BY r.created_at DESC LIMIT 6"); // 获取最新资源 $latest = $db->query("SELECT r.*, c.name as cat_name, c.slug as cat_slug, u.username FROM resources r LEFT JOIN categories c ON r.category_id = c.id LEFT JOIN users u ON r.user_id = u.id WHERE r.status='approved' ORDER BY r.created_at DESC LIMIT 12"); // 热门下载 $popular = $db->query("SELECT r.*, c.name as cat_name, c.slug as cat_slug, u.username FROM resources r LEFT JOIN categories c ON r.category_id = c.id LEFT JOIN users u ON r.user_id = u.id WHERE r.status='approved' ORDER BY r.download_count DESC LIMIT 6"); ?>

发现优质资源
助力高效创作

ResHub 汇聚海量软件工具、文档模板、源码素材与影音资源,一键下载,即刻使用。

资源总数
累计下载
注册用户
资源分类

📂 资源分类

查看全部 →
fetch_assoc()): ?>

个资源
num_rows > 0): ?>

⭐ 精选推荐

fetch_assoc()): ?>

🆕 最新资源

更多 →
fetch_assoc()): ?>
num_rows > 0): ?>

🔥 热门下载

fetch_assoc()): ?>
'💻', 'document' => '📄', 'source' => '📝', 'media' => '🎬', 'other' => '📦']; $icon = $icons[$res['cat_slug'] ?? 'other'] ?? '📦'; $ratingStars = str_repeat('⭐', floor($res['rating_avg'] ?? 0)); if (($res['rating_avg'] ?? 0) - floor($res['rating_avg'] ?? 0) >= 0.5) $ratingStars .= '⭐'; $title = htmlspecialchars($res['title']); $desc = htmlspecialchars(mb_substr($res['description'] ?? '', 0, 80)); $catName = htmlspecialchars($res['cat_name'] ?? '未分类'); $username = htmlspecialchars($res['username'] ?? '匿名'); $downloads = number_format($res['download_count'] ?? 0); $fileSize = formatSize($res['file_size'] ?? 0); $fileType = htmlspecialchars($res['file_type'] ?? ''); $id = $res['id']; $ratingAvg = $res['rating_avg'] ?? 0; $ratingCount = $res['rating_count'] ?? 0; return <<
{$icon} {$fileType}

{$title}

{$desc}

📁 {$catName} 👤 {$username} 💾 {$fileSize}
HTML; } function formatSize($bytes) { if ($bytes == 0) return 'N/A'; $units = ['B', 'KB', 'MB', 'GB']; $i = floor(log($bytes, 1024)); return round($bytes / pow(1024, $i), 1) . ' ' . $units[$i]; } function displayCategoryPage($catSlug) { global $db; $sort = $_GET['sort'] ?? 'newest'; $orderBy = 'r.created_at DESC'; if ($sort === 'popular') $orderBy = 'r.download_count DESC'; if ($sort === 'rating') $orderBy = 'r.rating_avg DESC'; $whereClause = "r.status='approved'"; $catName = '全部资源'; if ($catSlug && $catSlug !== 'all') { $stmt = $db->prepare("SELECT name FROM categories WHERE slug = ?"); $stmt->bind_param("s", $catSlug); $stmt->execute(); $catResult = $stmt->get_result(); if ($catRow = $catResult->fetch_assoc()) { $catName = $catRow['name']; $whereClause .= " AND c.slug = '" . $db->real_escape_string($catSlug) . "'"; } $stmt->close(); } $perPage = 20; $pageNum = max(1, intval($_GET['p'] ?? 1)); $offset = ($pageNum - 1) * $perPage; $countSql = "SELECT COUNT(*) as cnt FROM resources r LEFT JOIN categories c ON r.category_id = c.id WHERE $whereClause"; $totalCount = $db->query($countSql)->fetch_assoc()['cnt']; $totalPages = ceil($totalCount / $perPage); $sql = "SELECT r.*, c.name as cat_name, c.slug as cat_slug, u.username FROM resources r LEFT JOIN categories c ON r.category_id = c.id LEFT JOIN users u ON r.user_id = u.id WHERE $whereClause ORDER BY $orderBy LIMIT $perPage OFFSET $offset"; $resources = $db->query($sql); ?>

📂

最新 最热 评分最高

共找到 个资源

num_rows > 0): ?> fetch_assoc()): ?>

暂无资源,上传一个吧

1): ?> prepare("SELECT r.*, c.name as cat_name, c.slug as cat_slug, u.username, u.avatar FROM resources r LEFT JOIN categories c ON r.category_id = c.id LEFT JOIN users u ON r.user_id = u.id WHERE r.id = ? AND r.status='approved'"); $stmt->bind_param("i", $id); $stmt->execute(); $res = $stmt->get_result()->fetch_assoc(); if (!$res) { echo '

😕 资源不存在或已下架

返回首页
'; return; } $stmt->close(); // 更新浏览数 $db->query("UPDATE resources SET view_count = view_count + 1 WHERE id = $id"); $icons = ['software' => '💻', 'document' => '📄', 'source' => '📝', 'media' => '🎬', 'other' => '📦']; $icon = $icons[$res['cat_slug'] ?? 'other'] ?? '📦'; $ratingStars = str_repeat('⭐', floor($res['rating_avg'] ?? 0)); if (($res['rating_avg'] ?? 0) - floor($res['rating_avg'] ?? 0) >= 0.5) $ratingStars .= '⭐'; // 获取评论 $comments = $db->query("SELECT co.*, u.username FROM comments co LEFT JOIN users u ON co.user_id = u.id WHERE co.resource_id = $id ORDER BY co.created_at DESC LIMIT 50"); // 当前用户评分 $userRating = 0; if (isset($_SESSION['user_id'])) { $urResult = $db->query("SELECT rating FROM ratings WHERE resource_id = $id AND user_id = " . intval($_SESSION['user_id'])); if ($urRow = $urResult->fetch_assoc()) $userRating = $urRow['rating']; } ?>

📁 👤 📅 👁️ 浏览 下载 (分 / 评)

📝 资源描述

💬 评论 (num_rows ?>)

登录后发表评论

fetch_assoc()): ?>

num_rows == 0): ?>

暂无评论,来说两句吧~

·

⬇ 立即下载

⭐ 评分

当前: (人评分)


📅 发布于

🔄 更新于

🔒 请先登录

上传资源需要登录账户

'; return; } global $db; $categories = $db->query("SELECT * FROM categories ORDER BY sort_order"); ?>

📤 上传资源

🔍 请输入搜索关键词

'; return; } $likeQuery = '%' . $db->real_escape_string($q) . '%'; $sql = "SELECT r.*, c.name as cat_name, c.slug as cat_slug, u.username FROM resources r LEFT JOIN categories c ON r.category_id = c.id LEFT JOIN users u ON r.user_id = u.id WHERE r.status='approved' AND (r.title LIKE '$likeQuery' OR r.description LIKE '$likeQuery') ORDER BY r.created_at DESC LIMIT 40"; $results = $db->query($sql); ?>

🔍 搜索: ""

找到 num_rows ?> 个结果

num_rows > 0): ?> fetch_assoc()): ?>

未找到相关资源,试试其他关键词吧

🔒 无权访问

仅管理员可访问后台

返回首页'; return; } global $db; $tab = $_GET['tab'] ?? 'dashboard'; ?>
📊 仪表盘 📦 资源管理 📂 分类管理 👥 用户管理 ← 返回前台
query("SELECT COUNT(*) as c FROM resources")->fetch_assoc()['c']; $userCount = $db->query("SELECT COUNT(*) as c FROM users")->fetch_assoc()['c']; $dlCount = $db->query("SELECT SUM(download_count) as c FROM resources")->fetch_assoc()['c'] ?? 0; $comCount = $db->query("SELECT COUNT(*) as c FROM comments")->fetch_assoc()['c']; echo "
"; echo "

$resCount

资源总数

"; echo "

$userCount

注册用户

"; echo "

$dlCount

总下载量

"; echo "

$comCount

总评论数

"; echo "
"; } elseif ($tab === 'resources') { $resources = $db->query("SELECT r.*, c.name as cat_name, u.username FROM resources r LEFT JOIN categories c ON r.category_id = c.id LEFT JOIN users u ON r.user_id = u.id ORDER BY r.created_at DESC LIMIT 100"); echo '
'; echo ''; echo ''; while ($r = $resources->fetch_assoc()) { $feat = $r['featured'] ? '✅' : '—'; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; } echo '
ID标题分类上传者下载评分精选操作
{$r['id']}" . htmlspecialchars(mb_substr($r['title'], 0, 30)) . "" . htmlspecialchars($r['cat_name']) . "" . htmlspecialchars($r['username'] ?? '—') . "{$r['download_count']}{$r['rating_avg']}$feat"; echo ""; echo "🗑"; echo "
'; } elseif ($tab === 'categories') { $cats = $db->query("SELECT c.*, COUNT(r.id) as cnt FROM categories c LEFT JOIN resources r ON c.id = r.category_id GROUP BY c.id ORDER BY c.sort_order"); echo '
'; echo ''; echo ''; while ($c = $cats->fetch_assoc()) { echo ""; } echo '
图标名称Slug资源数排序
{$c['icon']}{$c['name']}{$c['slug']}{$c['cnt']}{$c['sort_order']}
'; echo '

提示:分类管理请在数据库中直接操作,或通过 phpMyAdmin 管理。

'; } elseif ($tab === 'users') { $users = $db->query("SELECT id, username, email, role, created_at FROM users ORDER BY id DESC LIMIT 50"); echo '
'; echo ''; echo ''; while ($u = $users->fetch_assoc()) { echo ""; } echo '
ID用户名邮箱角色注册时间
{$u['id']}{$u['username']}{$u['email']}{$u['role']}{$u['created_at']}
'; } } // 输出页面前检查消息 $msg = $_GET['msg'] ?? ''; if ($msg === 'uploaded') echo ''; if ($msg === 'login_required') echo ''; if ($msg === 'deleted') echo ''; ?>``` ### 🚀 快速部署与使用指南 这份源码为您生成了一个可直接运行的资源下载平台,包含完整的前端界面和后端逻辑。您只需配置好PHP和MySQL环境,将代码保存为`index.php`文件即可启动。 **部署步骤(三步上线)** 1. **环境准备**:确保服务器已安装 **PHP 7.4+** 和 **MySQL 5.7+**,并开启了`mysqli`扩展。 2. **导入代码**:将上方完整代码复制并保存为 `index.php`,放置在网站根目录。 3. **修改配置**:找到文件开头的`DB_HOST`、`DB_USER`、`DB_PASS`常量,将其修改为您本地的数据库连接信息。 4. **首次访问**:在浏览器中访问该文件,系统会**自动创建数据库、数据表并插入默认管理员账户**。默认管理员账户为: * **用户名**:`admin` * **密码**:`admin123` (登录后请立即修改) ### ⚙️ 核心功能模块与操作 系统围绕资源上传、下载、管理三大主线设计,核心模块清晰易用: * **资源发现与下载**: * **首页**提供精选推荐、最新资源和热门下载展示,并支持按分类浏览。 * **资源详情页**展示完整描述、评分和评论,提供一键下载按钮,会记录下载日志并更新计数。 * **全局搜索**支持按资源标题和描述进行模糊检索。 * **用户系统与互动**: * 通过顶部导航栏的**登录/注册**模态框,用户可快速创建账户。 * 登录后,用户可在详情页**发表评论**和对资源进行**星级评分**,系统会自动计算平均分。 * **内容贡献与管理**: * 登录用户可通过“上传”按钮**提交新资源**,填写标题、选择分类并上传文件。 * **管理员后台**(仅admin账户可见)提供仪表盘概览,可管理所有资源(设为精选、删除)、查看分类和用户列表。 --- **优化建议:** 您可以修改文件顶部的`