prepare("SELECT file_path FROM driver_documents WHERE id = ?"); $stmt->execute([$doc_id]); $doc = $stmt->fetch(); if ($doc) { $filePath = '../' . $doc['file_path']; // ลบข้อมูลจากฐานข้อมูล $deleteStmt = $pdo->prepare("DELETE FROM driver_documents WHERE id = ?"); $deleteStmt->execute([$doc_id]); // ลบไฟล์จริงออกจากเซิร์ฟเวอร์ if (file_exists($filePath)) { unlink($filePath); } jsonResponse(true, 'ลบไฟล์สำเร็จ'); } else { jsonResponse(false, 'ไม่พบเอกสารที่ต้องการลบ'); } } catch (PDOException $e) { jsonResponse(false, 'Database Error: ' . $e->getMessage()); } ?>