简体   繁体   中英

PHP upload_max_filesize not obeyed

PHP /etc/php.ini is not obeying upload_max_filesize

Details: using <?php echo phpinfo(); ?> <?php echo phpinfo(); ?> I can see that the 'Loaded Configuration file' is /etc/php.ini

Within this file I have the values:

file_uploads = On
upload_max_filesize = 12M
post_max_size = 12M

BUT the phpinfo(); shows upload_max_filesize 2M

After restarting Apache serveral times this value is never obeyed whatever I change the upload_max_filesize and max_post_size.

I have worked around this issue by using a .htaccess directive

php_value upload_max_filesize 12M
php_value post_max_size 12M

This has allowed the upload value to be changed and the PHPINFO() now shows the value correctly.

Directive            Local Value    Master Value
upload_max_filesize  12M            2M

The question is : why is the /etc/php.ini file not being obeyed in the first place? Running CentOs 5.4 , php 5.3.29 Searched ( grep -inr '2M' * ) in /etc/php.d/* with nothing found.

Why is it not listening to the main php.ini file which it says it's using?

Already looked at PHP upload_max_filesize

and Changing upload_max_filesize on PHP

on SO with no success.

--UPDATE-- Search grep -inr 'upload_max_filesize in /etc/*.ini and .conf with only the 12M value being returned. Searched /etc/httpd/conf/ /etc/httpd/conf.d/ and obviously the root of the virtual host. No special setup in virtual hosts with grep returning 0 results.

Additional .ini files parsed
    /etc/php.d/bcmath.ini, /etc/php.d/curl.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, 
    /etc/php.d/gd.ini, /etc/php.d/intl.ini, /etc/php.d/json.ini, /etc/php.d/ldap.ini, 
    /etc/php.d/mbstring.ini, /etc/php.d/mcrypt.ini,
/etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini, /etc/php.d/posix.ini, /etc/php.d/soap.ini,    /etc/php.d/suhosin.ini, /etc/php.d/sysvmsg.ini, /etc/php.d/sysvsem.ini, etc/php.d/sysvshm.ini,
/etc/php.d/wddx.ini, /etc/php.d/xdebug.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlwriter.ini,
/etc/php.d/xsl.ini, /etc/php.d/zip.ini

If you examine the first few lines of the phpinfo() you can know
which php.ini is loaded.(courtesy @Raptor)

In your question you have mentioned that /etc/php.ini is indeed the one loaded.

In that case there is a chance that your httpd.conf contains something like below :

php_value upload_max_filesize somevalue

This is a global value which will be applied for all the sites.
I guess it may well override the php.ini settings.

我在网站的根目录中有 .htaccess 覆盖了 php.ini 中的这个值。

I lost quite a bit of time trying to figure this out as well. Turns out that this will happen if you are using php-fpm. The php.ini file will be read, phpinfo() will tell you that it's been read, but the max filesize value (as well as a few others) will be ignored.

I experienced this with a Centos8 install, and it took me far too long to notice that it was using php-fpm instead of mod_php, so all the arguments to mod_php were being ignored.

Your options are to either install mod_php or just configure php-fpm properly (better).

Try to set in your htaccess file. May be this might help you guys. It's working for me

php_value post_max_size 30M
php_value upload_max_filesize 25M
php_value upload_max_size 25M

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM