Changing upload_max_filesize to PHP

I am using PHP 5.3.0 and have encountered something that might be a bug (in this case I will report it), or maybe I am - so I ask you to make sure.

When running this code:

<?php ini_set('upload_max_filesize', '10M'); echo ini_get('upload_max_filesize'), ", " , ini_get('post_max_size') 

As a result, I:

 2M, 8M 

This is despite my php.ini installation being higher:

 upload_max_filesize = 10M post_max_size = 10M 

(happens only once)

Since the error occurs after setting the value, as well as setting it in php.ini, I tend to think that this is an error. Can someone confirm or tell me where I am going wrong?

Update : it seems that restarting Apache fixed this - I always thought that it does not need to be restarted if you changed php.ini.

+71
php upload
Jul 13 '09 at 10:22
source share
9 answers

You cannot use shorthand notation to set configuration values โ€‹โ€‹outside of PHP.ini. I assume that it returns to 2 MB as the compiled default value when encountering a bad value.

On the other hand, I do not think upload_max_filesize can be set using ini_set() . The "official" list claims to be PHP_INI_PERDIR .

+55
Jul 13 '09 at 22:28
source share

Do you use a hosting provider? These may be the main settings, overriding everything that you are trying to change. Have you tried adding them to your .htaccess?

 php_value upload_max_filesize 10M php_value post_max_size 10M 
+61
Jul 13 '09 at 22:27
source share

Since I just ran into this problem on a shared host and couldn't add values โ€‹โ€‹to my .htaccess file, I decided to share my solution.

I made an ini file with values โ€‹โ€‹in it. Plain:

Make a file named ".user.ini" and add your values

 upload_max_filesize = 150M post_max_size = 150M 

Boom, the problem is solved.

+32
Mar 14 '15 at 1:25
source share

I got this to work with the .user.ini file in the same directory as my index.php script, which loads my application. Here is the content:

 upload_max_filesize = "20M" post_max_size = "25M" 

This is the recommended solution for Heroku.

+7
Jan 12 '15 at 22:17
source share

This can also be controlled using the apache configuration. Check httpd.conf and / or .htaccess for the following:

 php_value upload_max_filesize 10M 
+2
Jul 13 '09 at 22:28
source share

if you use ini_set on the fly, you will find here http://php.net/manual/en/ini.core.php information, for example, upload_max_filesize and post_max_size do not change on the fly (PHP_INI_PERDIR).

Only changes to php.ini, .htaccess or vhost change these variables.

-one
May 31 '12 at 13:13
source share

If you are running on a local server such as wamp or xampp, make sure it uses php.ini, which you think so. These servers usually use php.ini by default, which are not in your dtml docs folder.

-one
Apr 19 '13 at 21:54
source share

I had the same problem, but I found out that not all configuration settings can be set using the ini_set () function, check this Where configuration configuration can be set

-one
May 18, '15 at 19:28
source share

You can also use in php file like

 <?php ini_set('upload_max_filesize', '200M'); ?> 
-eleven
Jun 07 '13 at 9:43 on
source share



All Articles