Reputation: 391
Im using Symfony 3.3 and configured a file upload like in the handbook.
https://symfony.com/doc/current/controller/upload_file.html
When editing my entity in a form, after the submission of the form, the image property (like in example "Brochure") is "null", even if set it before submit.
$entity->setBrochure(new File($this->getParameter('brochures_directory').'/'.$entity->getBrochure()));
So it is not possible to decide if the user really want to remove the image or if he wants to keep it.
Did I forgot something or how is it possible to correctly handle the image?
Thank you for your answers!
Best!
Upvotes: 2
Views: 896
Reputation: 87
It's due to HTML specifications: a file input can't be pre-filled.
A solution is to put another input submit with a different name (different than the default one). Only the button/input "clicked" by the user will be sent.
Detect it in the request; if exist, delete your file data.
And, in your view, display the original name (and/or size, type... whatever your want) near the input file.
Upvotes: 1