Bir*_*won 10 symfony-forms symfony
我遇到令牌和文件字段表单的问题.
表单的验证如下:
public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection(array(
'fields' => array(
'file' => new File(
array(
'maxSize' => '2M',
'mimeTypes' => array(
'application/pdf', 'application/x-pdf',
'image/png', 'image/jpg', 'image/jpeg', 'image/gif',
),
)
),
)
));
return array(
'validation_constraint' => $collectionConstraint
}
Run Code Online (Sandbox Code Playgroud)
当我上传一个无效的大小文件(~5MB)时,我得到了这个错误,这是我希望的:
The file is too large. Allowed maximum size is 2M bytes
Run Code Online (Sandbox Code Playgroud)
但是当我上传一个太大的文件(~30MB)时,错误会发生变化:
The CSRF token is invalid. Please try to resubmit the form
The uploaded file was too large. Please try to upload a smaller file
Run Code Online (Sandbox Code Playgroud)
问题是错误令牌.我的格式是{{form_rest(form)}}代码.我认为错误更改是因为:如何增加Symfony 2表单上文件的上传限制?
我不想增加上传限制.我希望令牌错误不显示.
小智 7
PHP(不是Symfony)如果文件大于您在以下位置配置的值,则拒绝该文件:
post_max_size
upload_max_filesize
Run Code Online (Sandbox Code Playgroud)
因此,抛出了csrf错误.
如果您想避免这种情况,则必须增加上传限制.这是唯一的方法.如果添加文件约束,则应该没有风险.