Search code examples
phpsymfonyxsdsymfony-formsfile-type

FIleType not being re-used when i submit my symfony form


I have a form, based on a non-entity, it's build with an XSD schema, my problem here is that when i submit my form, all is ok except the file ..

There is the treatement when I handle the submission of my form :

    $value[$sectionName]['photo'] ='/Upload/'.$field->getClientOriginalName();
                            $field->move($dir, $field->getClientOriginalName());

With the documentation : https://symfony.com/doc/current/controller/upload_file.html I supose that, to upload my file I just have to use the move() function.

The strangest thing is that the file is uploaded where I want, in my '/Upload' directory.

But when my page reload, in the form the FileType is blank with no file inside.

Thanks for the help by advance. And sorry for my bad english, hard morning !


Solution

  • This is the expected behaviour, so that if you submit the form again, the file won't be re-uploaded unnecessarily.

    It sounds to me like your upload code is working fine but you have a small misunderstanding of how the HTML File input behaves. The input field temporarily holds the path to the file on your local machine - not the uploaded file.

    If you want to see the uploaded file (path), you need to do some custom coding in your form to make that happen.