我有一个包含 FileType 字段的表单。我已将multiple
选项设置为,true
以便用户可以同时上传多个文件。
$builder->add('myFile', FileType::class, [
'label' => 'upload file',
'multiple' => true,
])
这是连接到此表单的实体中的相应属性:
/**
* @Assert\NotBlank()
* @Assert\File(mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"})
* @ORM\Column(type="array")
*/
private $myFile;
当我提交表单时,我收到错误:
UnexpectedTypeException in FileValidator.php line 168:
Expected argument of type "string", "array" given
我在 File assert 前面添加了花括号,所以它看起来像这样:
* @Assert\File{}(mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"})
现在提交表单时它不会抱怨。但也不检查文件类型验证。
知道如何使文件类型适用于多个选定的文件吗?