0

I'm trying to catch error for an oversize file upload.

My limit (MAX_FILE_SIZE in the form & also later for $_FILES['uploadFile']['size']) is 10Mb / 10485760 bytes

In php.ini, I have:

  • post_max_size = 30M
  • upload_max_filesize = 20M

Everytime I upload between 10M (the limit) and post_max_size (30M), error could be caught, but when it was exceed 30M, it would go straight to home address (in my case: http://project.dev/admin/), without any error being logged.

This is my HTML code:

<form class="form-horizontal" action="./skrip.php" method="post" name="thisForm" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10485760">
<label>Upload file</label>
<input class="upload" type="file" name="uploadFile" class="file" id="uploadFile">
<button>Submit</button
</form>

And this is my skrip.php

$displayMaxSize = ini_get('post_max_size') * 1024 * 1024;

if (  $_SERVER['CONTENT_LENGTH'] > $displayMaxSize
   || $_FILES['uploadFile']['size'] > 10485760) {
    throw new Exception('PHP discarded POST data because of request exceeding post_max_size.');
}

... continue to file validation

I tried accepted answer from this SO posts below but still fails:

PHP Warning: POST Content-Length of n bytes exceeds the limit of 3145728 bytes in Unknown on line 0

How to gracefully handle files that exceed PHP's `post_max_size`?

PHP - empty $_POST and $_FILES - when uploading larger files

sianipard
  • 164
  • 2
  • 17

0 Answers0