Files
biblio/src/Controller/FileController.php

44 lines
1.3 KiB
PHP

<?php
namespace App\Controller;
use App\Entity\Book;
use App\Entity\File;
use App\Repository\FileRepository;
use App\Service\FileService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class FileController extends AbstractController
{
#[Route('/file', name: 'app_file')]
public function index(): Response
{
return $this->render('file/index.html.twig', [
'controller_name' => 'FileController',
]);
}
#[Route('/file/delete/{id}', name: 'app_file_delete')]
public function delete(
Request $request,
FileRepository $fileRepository,
File $file,
FileService $fileService
): Response {
$fileService->removeFiles($file);
$fileRepository->remove($file, 'true');
return $this->redirect($request->headers->get('referer'));
}
#[Route('/file/{id}', name: 'app_file_download', methods: ['GET'])]
public function get(File $file, FileService $fileService)
{
return $this->file($fileService->getFilePath($file), $file->getFileName());
}
}