getConnection(); header('Content-Type: application/json'); $id = intval($_POST['id'] ?? 0); if ($id <= 0) { echo json_encode(['status' => 'error', 'message' => 'Invalid file ID']); exit; } try { // Recupera il nome del file $stmt = $pdo->prepare("SELECT filename FROM client_files WHERE id = ?"); $stmt->execute([$id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row && !empty($row['filename'])) { $filePath = __DIR__ . '/../uploads/client_files/' . $row['filename']; if (file_exists($filePath)) { unlink($filePath); // elimina file fisico } } // Cancella riga dal DB $pdo->prepare("DELETE FROM client_files WHERE id = ?")->execute([$id]); echo json_encode(['status' => 'ok']); } catch (Exception $e) { echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); }