Answer the question
In order to leave comments, you need to log in
How to properly load and display images in Symfony?
Learning Symfony 4 by making a blog and gallery.
The gallery has its own folder for uploading pictures, I specify it in the parameters:
parameters:
upload_directory: '%kernel.project_dir%/public/up'
gallery_upload: '%upload_directory%/gallery'
documents_upload: '%upload_directory%/docs'
files_upload: '%upload_directory%/files'
$uploadedFile = $request->files->get('image')['fileUploader'];
$fileName = $fileUploader->upload($uploadedFile, $this->getParameter('gallery_upload'));
$image->setImage($fileName);
<img src="/up/gallery/{{ image.filename }}">
parameters:
gallery_web: '/gallery/'
documents_web: '/docs/'
files_web: '/files/'
<img src="{{ getParameter('gallery_web') }}{{ image.filename }}">
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question