getConnection(); $stmt = $pdo->prepare('SELECT * FROM thesis_files WHERE id = ?'); $stmt->execute([$dbId]); $fileRow = $stmt->fetch(); if (!$fileRow) { http_response_code(404); die('Fichier introuvable.'); } // ── Move physical file to _trash/ for recovery ─────────────────────────── $filePath = $fileRow['file_path'] ?? ''; if ($filePath !== '' && !str_starts_with($filePath, 'peertube_ids:') && !str_starts_with($filePath, 'http://') && !str_starts_with($filePath, 'https://')) { $absPath = STORAGE_ROOT . '/' . $filePath; if (file_exists($absPath)) { $trashDir = STORAGE_ROOT . '/tmp/_trash'; if (!is_dir($trashDir)) { mkdir($trashDir, 0755, true); } $trashPath = $trashDir . '/' . basename($filePath); // Append db_id to avoid name collisions $trashPath = $trashDir . '/' . $dbId . '_' . basename($filePath); rename($absPath, $trashPath); } } // ── Soft-delete the row (set deleted_at timestamp) ─────────────────────── // thesis_files may not have a deleted_at column; delete outright for now. $delStmt = $pdo->prepare('DELETE FROM thesis_files WHERE id = ?'); $delStmt->execute([$dbId]); http_response_code(200); exit;