105

I get similar errors in my error_log in php when users are uploading their files

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

In my php.ini (created custom ini file in public_html) would this solve this problem, how much would I have to set it to around 1GB? I am going to change my settings to this in php.ini, will it solve the problem?

upload_max_filesize = 1000M ;1GB
post_max_size = 1000M

What would I set the 'memory_limit' limit to.

Also would this be correct in my script to check file uploaded size is <1GB

if($_FILES["uploadedfile"]["size"]<1000000)
7
  • 5
    Are you sure you are editing the correct php.ini?
    – Pekka
    Commented Jun 8, 2011 at 14:01
  • Are you editing the correct php.ini (there are several)? Is something else resetting the settings? (e.g. any calls to php_ini_set?) Commented Jun 8, 2011 at 14:01
  • I created a custom php.ini file in public_html
    – daza166
    Commented Jun 8, 2011 at 14:02
  • @daza: you can't just drop a php.ini anywhere you want.PHP only checks certain locations, and "current directory" isn't one of them. You can use 'php_value' directives in your httpd.conf and/or an .htaccess file to set in a particular directory. But otherwise you'll have to change it in the main .ini file. Use php_info() to see what your "local" settings are, and which .ini files are being used.
    – Marc B
    Commented Jun 8, 2011 at 14:10
  • 2
    make an info.php with <?php phpinfo(); ?> copy it to public_html and call it in your browser. Then check if upload_max_filesize has the right value.
    – DanielB
    Commented Jun 8, 2011 at 14:11

10 Answers 10

102

8388608 bytes is 8M, the default limit in PHP. Those changes to php.ini should indeed solve the problem (make sure your restart your Apache server after making them).

Memory limit shouldn't need to be changed here.

4
  • Make sure you restart your server after making the changes in .ini file.
    – Sandhu
    Commented Feb 3, 2016 at 8:39
  • 1
    If you are using nginx+php fpm make sure to restart the php daemon sudo service php5-fpm restart
    – Gourneau
    Commented Mar 16, 2016 at 3:58
  • 1
    Let me just post here my experience, the restart gave me a stop: Unknown instance:, it was just creating a new php5-fpm instance but my webserver was still using the old one, I then had to do sudo killall -KILL php5-fpm then sudo service php5-fpm start
    – Memes
    Commented May 11, 2016 at 8:29
  • Depending on what else is being done in the PHP process that handles the upload, it may be necessary to increase memory_limit to an amount larger than the desired max upload size. Commented Jun 19, 2020 at 21:44
49

I suggest that you should change to post_max_size from 8M to 32M in the php.ini file.

44

you just setting at php.ini

then set :

upload_max_filesize = 1000M;
post_max_size = 1000M;

then restart your xampp.. Check the image

0
20

Try pasting this to .htaccess and it should work.

php_value post_max_size 2000M
php_value upload_max_filesize 2500M
php_value max_execution_time 6000000
php_value max_input_time 6000000
php_value memory_limit 2500M
1
  • Can you be little bit more specific? should it be outsite IfModule or inside. i've pasted it outside IfModule and it is giving me server error. Commented Oct 30, 2021 at 7:53
14

post_max_size should be slightly bigger than upload_max_filesize, because when uploading using HTTP POST method the text also includes headers with file size and name, etc.

If you want to successfully uppload 1GiB files, you have to set:

upload_max_filesize = 1024M
post_max_size = 1025M

Note, the correct suffix for GB is G, i.e. upload_max_filesize = 1G.

No need to set memory_limit.

1
  • This is the one that saved me.
    – Joe
    Commented Feb 2, 2022 at 15:36
7

In Some cases, you need to increase the maximum execution time.

max_execution_time=30

I made it

max_execution_time=600000

then I was happy.

1
  • 9
    often you may not want to do this in php.ini because it would allow ALL php processes to run for that amount of time. You can set it in a single file with set_time_limit() e.g. set_time_limit(600000) Commented Jul 15, 2015 at 20:16
5

There might be more than just one php.ini file. For example, when using WAMP there are 2 php.ini files in following directories:

  • C:\wamp\bin\apache\apache2.4.9\bin
  • C:\wamp\bin\php\php5.5.12

You need to edit the first one.

0
5

I disagree, but the solution to increase the file size in php.ini or .htaccess won't work if the user sends a file larger than allowed by the server application.

I suggest validating this on the front end. For example:

$(document).ready(function() {
    $ ('#your_input_file_id').bind('change', function() {
        var fileSize = this.files[0].size/1024/1024;
        if (fileSize > 2) { // 2M
            alert('Your custom message for max file size exceeded');
            $('#your_input_file_id').val('');
        }
    });
});

4
  • 3
    Disagree with what?
    – Rob
    Commented Jun 30, 2017 at 2:28
  • 1
    It's fine to validate client side, but it doesn't do anything for security, only to give the user an immediate warning if they're uploading a large file. The whole objective here isn't to keep users from uploading a large file, it's to allow them to upload a large file. Commented Jul 14, 2018 at 3:13
  • 1
    Is there no server side solution/check to this? I can easily bypass a JS check.
    – akinuri
    Commented Jun 26, 2019 at 12:59
  • 1
    Nvm, figured it out: if ($_SERVER["CONTENT_LENGTH"] > (int)(str_replace("M", "", ini_get("post_max_size")) * 1024 * 1024)) { // do w/e
    – akinuri
    Commented Jun 26, 2019 at 13:11
3

If you are using Php 5.6.X versions in windows using Wamp, then file location may be in,

C:\Windows\php.ini

Just try with

post_max_size = 100M;

Try to do changes in Apache one. By that your Wamp/XAMP load .ini file

0

If you are using Laravel and using artisan:serve for running Laravel project you create php.ini in your public directory, then you can specify your configuration.

  • file_uploads = On
  • max_execution_time = 300
  • post_max_size = 20480M
  • upload_max_filesize = 20480M

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.