<?php
namespace App\Controller;
use App\Entity\Media;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class LinkToFileController extends AbstractController
{
#[Route('/file/{type}/{id}_{subtype}', name: 'app_link_to_file')]
public function index($id, EntityManagerInterface $em): Response
{
$media = $em->getRepository(Media::class)->findOneById($id);
$path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
return new BinaryFileResponse($path);
}
#[Route('/catalogue/droite', name: 'catalogue_droite')]
public function catalogue( EntityManagerInterface $em): Response
{
$media = $em->getRepository(Media::class)->findOneBy(
['name'=>'catalogue droite']
);
$path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
return new BinaryFileResponse($path);
}
#[Route('/catalogue/gauche', name: 'catalogue_gauche')]
public function catalogueG( EntityManagerInterface $em): Response
{
$media = $em->getRepository(Media::class)->findOneBy(
['name'=>'catalogue gauche']
);
$path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
return new BinaryFileResponse($path);
}
#[Route('/catalogue/show/{name}', name: 'catalogue_show_name')]
public function catalogueByName($name,EntityManagerInterface $em): Response
{
$media = $em->getRepository(Media::class)->findOneBy(
['name'=>$name]
);
$path = $media->getImgFile()->getPath()."/".$media->getImgFile()->getFilename();
return new BinaryFileResponse($path);
}
}