我提交symfony表单时不会重复使用FIleType

时间:2017-07-10 08:08:38

标签: php symfony xsd symfony-forms file-type

我有一个基于非实体的表单,它使用XSD架构构建,我的问题是,当我提交表单时,除文件外一切正常..

处理提交表单时有处理权:

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

使用文档:https://symfony.com/doc/current/controller/upload_file.html 我认为,要上传我的文件,我只需要使用move()函数。

最奇怪的是,文件上传到我想要的地方,在我的上传/上传中。目录。

但是当我的页面重新加载时,FileType为空白,内部没有文件。

感谢提前帮助。抱歉我的英语不好,早上好!

1 个答案:

答案 0 :(得分:0)

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.