prepare(" SELECT i.*, u.username, GROUP_CONCAT(t.name) as tag_names, GROUP_CONCAT(t.color) as tag_colors, GROUP_CONCAT(t.id) as tag_ids, (SELECT COUNT(*) FROM image_feedbacks WHERE image_id = i.id AND type = 'like') as like_count, (SELECT COUNT(*) FROM image_feedbacks WHERE image_id = i.id AND type = 'report') as report_count, (SELECT COUNT(*) FROM image_feedbacks WHERE image_id = i.id AND user_id = ? AND type = 'like') as user_liked FROM images i LEFT JOIN users u ON i.user_id = u.id LEFT JOIN image_tags it ON i.id = it.image_id LEFT JOIN tags t ON it.tag_id = t.id WHERE i.id = ? GROUP BY i.id "); $stmt->execute([$_SESSION['user_id'] ?? 0, $image_id]); $image = $stmt->fetch(PDO::FETCH_ASSOC); if (!$image) { die('图片不存在或已被删除'); } $tags = []; if ($image['tag_names']) { $tagNames = explode(',', $image['tag_names']); $tagColors = explode(',', $image['tag_colors']); $tagIds = explode(',', $image['tag_ids']); for ($i = 0; $i < count($tagNames); $i++) { if (!empty($tagNames[$i])) { $tags[] = [ 'id' => $tagIds[$i], 'name' => $tagNames[$i], 'color' => $tagColors[$i] ]; } } } if (!isset($_SESSION['viewed_images'])) { $_SESSION['viewed_images'] = []; } if (!in_array($image_id, $_SESSION['viewed_images'])) { $pdo->prepare("UPDATE images SET views = views + 1 WHERE id = ?")->execute([$image_id]); $_SESSION['viewed_images'][] = $image_id; } } catch(PDOException $e) { die('数据库错误: ' . $e->getMessage()); } if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SESSION['user_id'])) { $type = $_POST['type']; $comment = trim($_POST['comment'] ?? ''); try { $stmt = $pdo->prepare("SELECT id FROM image_feedbacks WHERE image_id = ? AND user_id = ? AND type = ?"); $stmt->execute([$image_id, $_SESSION['user_id'], $type]); if ($stmt->rowCount() > 0) { $feedback_error = '您已经对此图片进行过此操作'; } else { $stmt = $pdo->prepare("INSERT INTO image_feedbacks (image_id, user_id, type, comment) VALUES (?, ?, ?, ?)"); if ($stmt->execute([$image_id, $_SESSION['user_id'], $type, $comment])) { $feedback_success = $type === 'like' ? '感谢您的喜欢!' : '举报已提交,我们会尽快处理。'; if ($type === 'like' && $image['user_id'] != $_SESSION['user_id']) { sendNotification( $image['user_id'], 'image_feedback', '您的图片被喜欢了!', "用户 {$_SESSION['username']} 喜欢了您的图片「{$image['title']}」", "view-image.php?id={$image_id}" ); } header("Location: view-image.php?id={$image_id}"); exit; } } } catch(PDOException $e) { $feedback_error = '操作失败:' . $e->getMessage(); } } ?> <?php echo htmlspecialchars($image['title'] ?: '图片详情'); ?> - <?php echo SITE_NAME; ?>
<?php echo htmlspecialchars($image['title']); ?>

上传者
上传时间
浏览量
喜欢数
状态

图片反馈

分享链接

"; ?>
删除图片