-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
The File maxSize Constraint does not seem to work when post_max_size
has been reached. The request method is post, but the rest of all variables (including $files) is empty.
When the post is too big, the form will try to get validated via $form->isValid()
but since there are no values this goes wrong. Or to be more precise, nothing happens because the form was not marked as submitted.
Currently I did fix this by calling the following snippet before calling $form->isValid()
:
// First check or the filesize was too large, because in that case files global is empty
$params = new ServerParams();
if ($params->getContentLength() > $params->getPostMaxSize()) {
$form->get('file')->addError(
new FormError($this->get('translator')->trans('form.msg_max_post',
array(
'%contentSize%' => $document->formatFilesize($params->getContentLength()),
'%maxSize%' => '20 MB',
),
'validators'
))
);
}
Symfony has a FormValidator
, which even has a similar check like the above snippet.
My above snippet does work properly, but after commenting it, for the same request FormValidator->validate()
is not executed when the post is too large.
It seems to go wrong in the HttpFoundationRequestHandler where $request->request
and $request->files
are both empty.