Changing upload_max_filesize on PHP

2018-12-31 22:23发布

I'm using PHP 5.3.0 and have encountered something that might be a bug (in which case I'll report it) or might be me - so I'm asking 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')

I end up with:

2M, 8M

This is despite my php.ini setting these higher:

upload_max_filesize = 10M
post_max_size = 10M

(occuring only once)

Because the error occurs after setting the value as well as it being set in php.ini I'm inclined to think it's a bug. Can anyone confirm or point me where I'm going wrong?

Update: Looks like restarting Apache fixed this - I always thought it didn't need to be restarted if you changed php.ini.

标签: php upload
9条回答
妖精总统
2楼-- · 2018-12-31 22:54

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

php_value upload_max_filesize 10M
查看更多
大哥的爱人
3楼-- · 2018-12-31 23:02

Since I just ran in to this problem on a shared host and was unable to add the values to my .htaccess file I thought I'd share my solution.

I made an ini file with the values in it. Simple as that:

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

upload_max_filesize = 150M
post_max_size = 150M

Boom, problem solved.

查看更多
柔情千种
4楼-- · 2018-12-31 23:02

You can use also in the php file like this

<?php ini_set('upload_max_filesize', '200M'); ?>
查看更多
余生请多指教
5楼-- · 2018-12-31 23:04

if you use ini_set on the fly then you will find here http://php.net/manual/en/ini.core.php the information that e.g. upload_max_filesize and post_max_size is not changeable on the fly (PHP_INI_PERDIR).

Only a php.ini, .htaccess or vhost config change seems to change these variables.

查看更多
查无此人
6楼-- · 2018-12-31 23:07

If you are running in a local server, such as wamp or xampp, make sure it's using the php.ini you think it is. These servers usually default to a php.ini that's not in your html docs folder.

查看更多
浅入江南
7楼-- · 2018-12-31 23:08

I got this to work using a .user.ini file in the same directory as my index.php script that loads my app. Here are the contents:

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

This is the recommended solution for Heroku.

查看更多
登录 后发表回答