entityManager->find(MileageAllowance::class, $uriVariables['id']); if (null === $mileageAllowance) { throw new NotFoundHttpException('Mileage allowance not found.'); } $receiptPath = $mileageAllowance->getAmountReceiptPath(); if (null === $receiptPath) { throw new NotFoundHttpException('No amount receipt found for this mileage allowance.'); } $absolutePath = sprintf('%s/%s', $this->uploadDir, $receiptPath); if (!file_exists($absolutePath)) { throw new NotFoundHttpException('Amount receipt file not found.'); } $response = new BinaryFileResponse($absolutePath); $disposition = HeaderUtils::makeDisposition( HeaderUtils::DISPOSITION_ATTACHMENT, $mileageAllowance->getAmountReceiptName() ?? 'justificatif.pdf' ); $response->headers->set('Content-Disposition', $disposition); return $response; } }