<?php
if (session_status()===PHP_SESSION_NONE) session_start();
require_once __DIR__ . '/../config/db.php';

$id = (int)($_GET['id'] ?? 0);
if ($id) {
  // حذف الصورة
  $stmt = db()->prepare("SELECT image FROM blog_posts WHERE id=? LIMIT 1");
  $stmt->execute([$id]);
  if ($row = $stmt->fetch()) {
    $file = $row['image'];
    $path = __DIR__ . '/../uploads/' . $file;
    if (!empty($file) && is_file($path)) @unlink($path);
  }
  db()->prepare("DELETE FROM blog_posts WHERE id=? LIMIT 1")->execute([$id]);
}
header('Location: blog.php'); exit;
