Current File : /home/mecutoc/domains/room.mecutth.com/public_html/information/delete.php
<?php
session_start();
include("../database/dbconnect.php");

$sql = "SELECT * FROM information WHERE info_id = '{$_GET['id']}'";
$inform = $pdo_room->prepare($sql);
$inform->execute();
$row = $inform->fetch(PDO::FETCH_ASSOC);

$previous_url_file = $row['info_url_file']; //ไฟล์ pdf
$previous_image_file = $row['info_image_file']; //ไฟล์ poster

if (file_exists($previous_image_file)) {
    //ลบ file
    unlink($previous_url_file);
    unlink($previous_image_file);
    //ลบฐานข้อมูล
    $stmt = $pdo_room->prepare("DELETE FROM information WHERE info_id = '{$row['info_id']}'");
    $stmt->execute();

    if ($stmt) {
        echo json_encode([
            'delete' => 'true'
        ]);
    }
}