Hello.
When uploading a file that far exceeds the allowed size before form validation is performed, I get the:
Warning POST Content-Length of ... exceeds the limit of ...
How can I handle this error?
Hello.
When uploading a file that far exceeds the allowed size before form validation is performed, I get the:
Warning POST Content-Length of ... exceeds the limit of ...
How can I handle this error?
Do you use the validator Laminas\Validator\File\UploadFile
?
Yes.
In method getInputFilterSpecification():
[
'name' => self::ELEMENT_FILE,
'required' => true,
'validators' => [
[
'name' => \Laminas\Validator\File\UploadFile::class,
'options' => [
'messages' => [
\Laminas\Validator\File\UploadFile::NO_FILE => _('file_no_file_was_uploaded'),
],
],
],
[
'name' => \Laminas\Validator\File\Size::class,
'options' => [
'max' => '15MB',
'messages' => [
\Laminas\Validator\File\Size::TOO_SMALL => _('file_to_small'),
\Laminas\Validator\File\Size::TOO_BIG => _('file_to_large'),
],
],
],
[
'name' => \Laminas\Validator\File\Extension::class,
'options' => [
'extension' => 'xls, xlsx, csv, ods',
'message' => _('file_extension_error'),
],
],
[
'name' => \Laminas\Validator\File\MimeType::class,
'options' => [
'mimeType' => 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/csv, application/vnd.oasis.opendocument.spreadsheet',
'message' => _('file_type_error'),
],
],
],
'filters' => [
],
],
For the max option in the Size validator, you could try to enter the full numeric value. For example, instead of 2MB, it should be 2000000.
Also, remember to check the PHP and apache settings.
Unfortunately, I still get this error. Before the form validation is done the server returns a warning.
I think you mean before any PHP code of your script / application is executed, right?
This is an older post but I just ran across this issue in one of my applications and I couldn’t find a solution if the file exceeds the max post size so what I did was used jquery to not allow them to click submit with a file over the size like so:
<script type="text/javascript">
$('#file').on('change', function() {
const size =
(this.files[0].size / 1024 / 1024).toFixed(2);
if (size > 8 ) {
alert("This file is too large. File must be less than 8 MB !");
$("#submitbutton").attr("disabled","disabled");
}else{
$("#submitbutton").attr("disabled",false);
}
});
</script>