src/Controller/LinkToFileController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Media;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class LinkToFileController extends AbstractController
  10. {
  11. #[Route('/file/{type}/{id}_{subtype}', name: 'app_link_to_file')]
  12. public function index($id, EntityManagerInterface $em): Response
  13. {
  14. $media = $em->getRepository(Media::class)->findOneById($id);
  15. $path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
  16. return new BinaryFileResponse($path);
  17. }
  18. #[Route('/catalogue/droite', name: 'catalogue_droite')]
  19. public function catalogue( EntityManagerInterface $em): Response
  20. {
  21. $media = $em->getRepository(Media::class)->findOneBy(
  22. ['name'=>'catalogue droite']
  23. );
  24. $path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
  25. return new BinaryFileResponse($path);
  26. }
  27. #[Route('/catalogue/gauche', name: 'catalogue_gauche')]
  28. public function catalogueG( EntityManagerInterface $em): Response
  29. {
  30. $media = $em->getRepository(Media::class)->findOneBy(
  31. ['name'=>'catalogue gauche']
  32. );
  33. $path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
  34. return new BinaryFileResponse($path);
  35. }
  36. #[Route('/catalogue/show/{name}', name: 'catalogue_show_name')]
  37. public function catalogueByName($name,EntityManagerInterface $em): Response
  38. {
  39. $media = $em->getRepository(Media::class)->findOneBy(
  40. ['name'=>$name]
  41. );
  42. $path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
  43. return new BinaryFileResponse($path);
  44. }
  45. }