Added twig extension to format file size, links to download and delete files attached to the book.

This commit is contained in:
krzysiej
2022-05-24 11:22:35 +02:00
parent 319f6311fc
commit 1f852ac031
5 changed files with 94 additions and 18 deletions

View File

@@ -99,9 +99,9 @@ class BookController extends AbstractController
$ebook->move(
$this->getParameter('book_files'),
'ebook_' . $book->getId() . '_' . md5(
$ebook->getClientOriginalName()
) . '.' . $ebook->guessClientExtension()
'ebook_' . $book->getId() . '_' .
md5($file->getFileName()) . '.' .
$file->getExtension()
);
}
}
@@ -126,16 +126,4 @@ class BookController extends AbstractController
return $this->redirectToRoute('app_book_index', [], Response::HTTP_SEE_OTHER);
}
#[Route('/download/{id}', name: 'app_book_download', methods: ['GET'])]
public function downloadBook(Book $book): BinaryFileResponse
{
return $this->file(
$this->getParameter('book_files') . '/' . 'ebook_' . $book->getId() . '.' . pathinfo(
$book->getOriginalFilename(),
PATHINFO_EXTENSION
),
$book->getOriginalFilename()
);
}
}