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)
daza166
  • 3,543
  • 10
  • 35
  • 41
  • 5
    Are you sure you are editing the correct php.ini? – Pekka Jun 08 '11 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`?) – Piskvor left the building Jun 08 '11 at 14:01
  • I created a custom php.ini file in public_html – daza166 Jun 08 '11 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 Jun 08 '11 at 14:10
  • 2
    make an info.php with `` copy it to public_html and call it in your browser. Then check if upload_max_filesize has the right value. – DanielB Jun 08 '11 at 14:11
  • my phpinfo() says its correct now changed to upload_max_filesize = 1000M and post_max_size = 1000M. Should that solve this issue now? – daza166 Jun 08 '11 at 14:19
  • Make sure you're updating the correct php.ini: https://stackoverflow.com/a/58999601/470749 – Ryan Nov 22 '19 at 18:09

10 Answers10

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.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Make sure you restart your server after making the changes in .ini file. – Sandhu Feb 03 '16 at 08:39
  • 1
    If you are using nginx+php fpm make sure to restart the php daemon `sudo service php5-fpm restart` – Gourneau Mar 16 '16 at 03:58
  • 1
    The restart did it for me. +1 Thanks ;) – Refilon Mar 28 '16 at 11:01
  • 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 May 11 '16 at 08: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. – Craig Finch Jun 19 '20 at 21:44
49

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

John
  • 1
  • 13
  • 98
  • 177
manson
  • 491
  • 4
  • 2
44

you just setting at php.ini

then set :

upload_max_filesize = 1000M;
post_max_size = 1000M;

then restart your xampp.. Check the image

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Farid Blaster
  • 974
  • 1
  • 9
  • 23
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
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Mel
  • 209
  • 2
  • 4
  • 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. – Alauddin Ahmed Oct 30 '21 at 07:53
13

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.

ArticIceJuice
  • 155
  • 1
  • 6
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.

Traveling Salesman
  • 2,209
  • 11
  • 46
  • 83
  • 8
    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) – billrichards Jul 15 '15 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.

sepehr
  • 17,110
  • 7
  • 81
  • 119
Irfandi D. Vendy
  • 894
  • 12
  • 20
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('');
        }
    });
});
pbarney
  • 2,529
  • 4
  • 35
  • 49
Marcio Muzzi
  • 51
  • 1
  • 2
  • 3
    Disagree with what? – Rob Jun 30 '17 at 02: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. – Altimus Prime Jul 14 '18 at 03:13
  • 1
    Is there no server side solution/check to this? I can easily bypass a JS check. – akinuri Jun 26 '19 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 Jun 26 '19 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

Edward Peters
  • 3,623
  • 2
  • 16
  • 39
Satyanarayana
  • 139
  • 1
  • 4
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