How to/can not set php.ini values in run time using ini_set() method?

为君一笑 提交于 2019-12-11 13:25:23

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/12103807/how-to-can-not-set-php-ini-values-in-run-time-using-ini-set-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!