D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
skyconb
/
newsyacine
/
Filename :
delete_article.php
back
Copy
<?php // =============================================== // delete_article.php (حذف مقال موجود) // =============================================== session_start(); include 'db_connect.php'; // 1. التحقق من الصلاحية (مهم جداً لأمان عملية الحذف) $is_admin = ($_SESSION['admin_logged_in'] ?? false) === true && ($_SESSION['admin'] ?? 'user') === 'admin'; if (!$is_admin) { $_SESSION['error'] = "ليس لديك الصلاحية لحذف المقالات."; header("Location: admin.php?section=articles"); exit(); } // 2. التحقق من وجود معرّف المقال في الرابط $article_id = $_GET['id'] ?? 0; if ($article_id > 0) { // =============================================== // 3. حذف الصورة المرتبطة أولاً (لتنظيف مجلد uploads) // =============================================== $get_image_sql = "SELECT thumbnail_url FROM articles WHERE id = ?"; $get_image_stmt = $conn->prepare($get_image_sql); $get_image_stmt->bind_param("i", $article_id); $get_image_stmt->execute(); $result = $get_image_stmt->get_result(); $image_row = $result->fetch_assoc(); $get_image_stmt->close(); if ($image_row && !empty($image_row['thumbnail_url'])) { $image_path = $image_row['thumbnail_url']; // التأكد من وجود الملف وحذفه if (file_exists($image_path) && !is_dir($image_path)) { unlink($image_path); } } // =============================================== // 4. تنفيذ عملية الحذف من قاعدة البيانات // =============================================== $delete_sql = "DELETE FROM articles WHERE id = ?"; $delete_stmt = $conn->prepare($delete_sql); $delete_stmt->bind_param("i", $article_id); if ($delete_stmt->execute()) { $_SESSION['message'] = "تم حذف المقال بنجاح."; } else { $_SESSION['error'] = "خطأ في الحذف: " . $delete_stmt->error; } $delete_stmt->close(); } else { $_SESSION['error'] = "معرّف المقال غير صالح للحذف."; } $conn->close(); // 5. التوجيه إلى صفحة إدارة المقالات header("Location: admin.php?section=articles"); exit(); ?>