0

I am trying to write a File Upload module in Codeigniter 3.1.11. Maximum file size has been set at 20Mb with

$config['max_size'] = 20480;

PHP upload limit is 40Mb.

But, when I run it and try to upload a heavy file, it does not redirect properly and loads the same form with

<br />
<b>Warning</b>:  POST Content-Length of 368347418 bytes exceeds the limit of 41943040 bytes in <b>Unknown</b> on line <b>0</b><br />
<!DOCTYPE html>
<html lang="en" class="h-100">

at the begining of the Html code.

I believe this is because the php size limit gets tripped first before the codeigniter limit can work and redirect properly. How do I solve this?

P.S.:

  1. I do not want to upload that file. I want that error. But I want to catch the error properly and redirect to some other page, instead of it getting posted over html. I have written that part of the code in Codeigniter, but this error is thrown before that portion of the code executes I believe.
  2. This error does not occur when the file size is higher than Codeigniter limit but less than PHP limit. Then the error is caught properly by Codeigniter and redirection code works perfect.
  • check the .htaccess part of: https://stackoverflow.com/questions/38968599/warning-post-content-length-of-90612004-bytes-exceeds-the-limit-of-8388608-byte – Vickel Jun 10 '21 at 13:02
  • Yes. But my problem is different. I do not want to upload that file. I want that error. But I want to catch the error properly and redirect to some other page, instead of it getting posted over html. I have written that part of the code in Codeigniter, but this error is thrown before that portion of the code executes I believe. – Arnab Roychoudhury Jun 10 '21 at 13:09
  • 1
    You should edit your question with that comment of yours, to make it clearer what you need – Vickel Jun 10 '21 at 13:12

1 Answers1

0

I have found a workaround on the Client side:

I need to add a JS script:

<script>
var uploadField = document.getElementById("file");

uploadField.onchange = function() {
    if(this.files[0].size > 20971520){
       alert("File is too big! Maximum limit is 20Mb");
       this.value = "";
    };
};
</script>

This stops the input to accept any file bigger than my Codeigniter limit, that automatically avoids the PHP limit (which is bigger than the Codeigniter limit).