Laminas form + upload file + POST Content-Length

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?