Answer the question
In order to leave comments, you need to log in
Symfony forms how to make file upload optional?
I pass the object retrieved by id to the form, initially each object receives an image when it is created. But when editing, it again requires you to upload a picture to it
->add('img',FileType::class, array(
'required' => false,
))
/**
* @ORM\Column(type="string", nullable=true)
* @Assert\File(mimeTypes={ "image/jpeg" })
*/
private $img;
Answer the question
In order to leave comments, you need to log in
The documentation is all about how to upload files
When creating a form to edit an already persisted item, the file form type still expects a File instance. As the persisted entity now contains only the relative file path, you first have to concatenate the configured upload path with the stored filename and create a new File class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question