prepare("SELECT file_path FROM vehicle_documents WHERE id = ?"); $stmt->execute([$doc_id]); $doc = $stmt->fetch(PDO::FETCH_ASSOC); if ($doc) { // Delete physical file $physical_path = '../' . $doc['file_path']; if (file_exists($physical_path)) { unlink($physical_path); } // Delete DB record $stmtDelete = $pdo->prepare("DELETE FROM vehicle_documents WHERE id = ?"); $stmtDelete->execute([$doc_id]); jsonResponse(true, 'ลบเอกสารสำเร็จ'); } else { jsonResponse(false, 'ไม่พบเอกสารที่ต้องการลบ'); } } catch (PDOException $e) { jsonResponse(false, 'DB Error: ' . $e->getMessage()); } ?>