src/Controller/DefaultController.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. class DefaultController extends AbstractController
  7. {
  8.     /**
  9.      * @Route("/", name="default")
  10.      */
  11.     public function index()
  12.     {
  13.         return $this->render('main/index.html.twig', [
  14.             'controller_name' => 'DefaultController',
  15.         ]);
  16.     }
  17.     /**
  18.      * @Route("/administracion", name="default")
  19.      */
  20.     public function indexAdministracion()
  21.     {
  22.         return $this->render('administracion/index.html');
  23.     }
  24.     /**
  25.      * @param $filename
  26.      * @Route("/download/{filename}")
  27.      *
  28.      */
  29.     public function downloadAction($filename)
  30.     {
  31.     //    $request = $this->get('request');
  32.     /*    $path = $this->get('kernel')->getRootDir(). "/../public/downloads/";
  33.         $content = file_get_contents($path.$filename);
  34.         $response = new Response();
  35.         //set headers
  36.         $response->headers->set('Content-Type', 'mime/type');
  37.         $response->headers->set('Content-Disposition', 'attachment;filename="'.$filename);
  38.         $response->setContent($content);*/
  39.         $response = new BinaryFileResponse("/download/".$filename);
  40.         return $response;
  41.     }
  42. }