PHP Post_Max_Size Overrides Upload_Max_Filesize

overriding upload_max_filesize

Those settings are not going to have any effect when set via ini_set.

The reason is that PHP needs those values before your script is even executed. When an upload occurs, the target script is executed when the upload is complete, so PHP needs to know the maximum sizes beforehand.

Set them in php.ini, your virtual host config, or in a .htaccess file. A typical .htaccess file would look like this:

php_value post_max_size 30M
php_value upload_max_filesize 30M

PHP post_max_size vs upload_max_filesize, what is the difference?

You are correct. post_max_size is the maximum size for all POST body data. It doesn't matter if you're POSTing JSON or your DVD collection, this is all POST body data. Your file upload counts towards this limit. You should also be aware that if you are uploading multiple files, the total file size has to fit within this limit.

upload_max_filesize is a maximum size only for files that are POSTed. Other types of POST body data are not subject to this limit.

In short, if you want to upload large files, you must increase both limits.

How to override upload_max_filesize in php.ini in docker image

Use UPLOAD_LIMIT env variable.
Documentation

UPLOAD_LIMIT - if set, will override the default value for apache and php-fpm (format as [0-9+](K,M,G) default value is 2048K, this will change upload_max_filesize and post_max_size values)

Example:

phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
hostname: phpmyadmin.local
ports:
- "8080:80"
environment:
PMA_HOST: mysql
PMA_USER: root
PMA_PASSWORD: password
UPLOAD_LIMIT: 64M

PHP post_max_size local value overridden by master value on Plesk / IIS?

As it turns out, on Windows, you can only set ini directives that are marked PHP_INI_USER per directory. Unfortunately, upload_max_filesize and post_max_size are both PHP_INI_PERDIR. From the PHP docs at http://php.net/manual/en/configuration.changes.php

The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values under the key should have the name of the PHP configuration directive and the string value. PHP constants in the values are not parsed. However, only configuration values changeable in PHP_INI_USER can be set this way, PHP_INI_PERDIR values can not.

So even though Plesk has an interface to change those directives, and even though phpinfo() picks up on them, they do nothing to change the actual max upload sizes. Plesk should not allow you to change those on Windows, and phpinfo() should not report the change, but what can you do.

Changing upload_max_filesize on PHP

You can't use shorthand notation to set configuration values outside of PHP.ini. I assume it's falling back to 2MB as the compiled default when confronted with a bad value.

On the other hand, I don't think upload_max_filesize could be set using ini_set(). The "official" list states that it is PHP_INI_PERDIR .

Change the maximum upload file size

You need to set the value of upload_max_filesize and post_max_size in your php.ini :

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M

After modifying php.ini file(s), you need to restart your HTTP server to use the new configuration.

If you can't change your php.ini, you're out of luck. You cannot change these values at run-time; uploads of file larger than the value specified in php.ini will have failed by the time execution reaches your call to ini_set.

See the Description of core php.ini directives.

How Can I change the post_max_size in php.ini file?

One of the biggest pitfalls for changing PHP.ini configurations is, that you use the wrong file. So create a php file with following content:

<?php
phpinfo();

There you will get a table with the most important infos about your installation. Have a look at the row of the php.ini file, which will look maybe like this:

Loaded Configuration File:  C:\xampp\php\php.ini

Make your changes to this file (from your phpinfo()). After every change, you have to restart your Apache.



Related Topics



Leave a reply



Submit