How to/can not set php.ini values in run time usin

2019-08-06 23:05发布

I am using nginx as web server and when I do phpinfo(); it uses /etc/php5/fpm/php.ini

Now in my php code I am trying to set file upload size and max file uploads using following code.

ini_set('max_file_uploads', "50");     
ini_set('upload_max_filesize', '250M');

But when I do ini_get('max_file_uploads') and echo the value it shows the default value as 20, infact I am not able to change any of the ini values in run time using ini_set().

Any ideas on how to change these values in run time using php code?

Thanks.

标签: nginx php ini
1条回答
ゆ 、 Hurt°
2楼-- · 2019-08-06 23:55

Not all PHP ini directives can be changed at runtime (via ini_set). See the file uploads section of the PHP manual and the definition of the changeability values, which are PHP_INI_SYSTEM and PHP_INI_PERDIR for your desired settings, neither of which can be set at runtime.

To get these settings in only one part of your app, you'll likely need to compromise and set max_file_uploads setting globally in your php.ini file (since it is PHP_INI_SYSTEM), and then use your favorite per-directory config mechanism (.htaccess, .user.ini (in >5.3), etc) to set upload_max_filesize for that particular part of your app. See here for good instructions.

查看更多
登录 后发表回答