entityManager->find(Formation::class, $uriVariables['id']); if (null === $formation) { throw new NotFoundHttpException('Formation not found.'); } $justificatifPath = $formation->getJustificatifPath(); if (null === $justificatifPath) { throw new NotFoundHttpException('No justificatif found for this formation.'); } $absolutePath = sprintf('%s/%s', $this->uploadDir, $justificatifPath); if (!file_exists($absolutePath)) { throw new NotFoundHttpException('Justificatif file not found.'); } $response = new BinaryFileResponse($absolutePath); $disposition = HeaderUtils::makeDisposition( HeaderUtils::DISPOSITION_ATTACHMENT, $formation->getJustificatifName() ?? 'justificatif.pdf' ); $response->headers->set('Content-Disposition', $disposition); return $response; } }