symfony-docs
symfony-docs copied to clipboard
Fix File Upload Example
Currently the example suggests to execute this code when doing edit
$product->setBrochureFilename(
new File($this->getParameter('brochures_directory').'/'.$product->getBrochureFilename())
);
this is wrong in couple of ways
First the setBrochureFilename
method expects string and not a File
instance. No error is thrown because the File
instance can be casted to string
and will return the full path, which is not what's needed. In the database field you need to store the filename only, and not the full path.
Second the form expects File
instance and not the entity. This is why the form data needs to be changed and not the entity.
In the 4.4 branch it's the same.
The explanation looks reasonable to me, WDYT @javiereguiluz ?