# Laminas form + upload file + POST Content-Length

**URL:** <https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253>\
**Category:** Components & MVC\
**Tags:** laminas-form\
**Created:** [April 19, 2021, 12:35am UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253 "2021-04-19T00:35:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kriss\_Kals](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/kriss_kals/32/1295_2.png) [@Kriss\_Kals](https://discourse.laminas.dev/u/Kriss_Kals)\
**Post date:** [April 19, 2021, 12:35am UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253/1 "2021-04-19T00:35:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 20, 2021, 7:58am UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253/2 "2021-04-20T07:58:40Z")

</div>

> [@Kriss\_Kals](#):
>
> How can I handle this error?

Do you use the [validator `Laminas\Validator\File\UploadFile`](https://docs.laminas.dev/laminas-validator/validators/file/upload-file/)?

---

<div class="post-metadata">

**Author:** ![Kriss\_Kals](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/kriss_kals/32/1295_2.png) [@Kriss\_Kals](https://discourse.laminas.dev/u/Kriss_Kals)\
**Post date:** [April 20, 2021, 9:26am UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253/3 "2021-04-20T09:26:14Z")

</div>

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' => [
			],
		],
```

---

<div class="post-metadata">

**Author:** ![royyong](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/royyong/32/875_2.png) [@royyong](https://discourse.laminas.dev/u/royyong)\
**Post date:** [April 24, 2021, 5:52am UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253/4 "2021-04-24T05:52:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kriss\_Kals](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/kriss_kals/32/1295_2.png) [@Kriss\_Kals](https://discourse.laminas.dev/u/Kriss_Kals)\
**Post date:** [April 26, 2021, 3:27pm UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253/5 "2021-04-26T15:27:26Z")

</div>

Unfortunately, I still get this error. Before the form validation is done the server returns a warning.

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [April 26, 2021, 7:17pm UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253/6 "2021-04-26T19:17:29Z")

</div>

> [@Kriss\_Kals](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![williamgall](https://avatars.discourse-cdn.com/v4/letter/w/b77776/32.png) [@williamgall](https://discourse.laminas.dev/u/williamgall)\
**Post date:** [August 6, 2024, 4:47pm UTC](https://discourse.laminas.dev/t/laminas-form-upload-file-post-content-length/2253/7 "2024-08-06T16:47:41Z")

</div>

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:

```auto
      <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>

```
