Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,47 @@
<?php
session_start();
require_once '../includes/db.php';
require_once '../includes/api_helper.php';
if (!isset($_SESSION['user_id'])) {
jsonResponse(false, 'Unauthorized', [], 401);
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
jsonResponse(false, 'Invalid request method');
}
// รับข้อมูลแบบ JSON หรือ Form Data
$data = json_decode(file_get_contents("php://input"), true) ?: $_POST;
$doc_id = $data['id'] ?? '';
if (empty($doc_id)) {
jsonResponse(false, 'Document ID is required');
}
try {
// ดึงข้อมูลไฟล์เพื่อเอา path ไปลบไฟล์จริง
$stmt = $pdo->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());
}
?>