I'm having problem with token and file field form.
The validation of the form is like this:
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
}
When I upload a invalid size file(~5MB) I get this error which is what I hope:
The file is too large. Allowed maximum size is 2M bytes
But when I upload a too big file(~30MB) the error changes:
The CSRF token is invalid. Please try to resubmit the form
The uploaded file was too large. Please try to upload a smaller file
The problem is the error token. I've in my form the {{ form_rest(form) }} code. I think the error change is because of this: How to increase the upload limit for files on a Symfony 2 form?
I don't want to increase the upload limit. I want the token error doesn't show.
PHP (not Symfony) rejects the file if it is bigger than your configured values in:
post_max_size
upload_max_filesize
Because of this the csrf-error is thrown.
If you want to avoid this you have to increase the upload limit. It is the only way. If you add your file-constraint this should be no risk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With