方法在运行时设置php

方法在运行时设置php

本文介绍了如何/不能使用ini_set()方法在运行时设置php.ini值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将nginx用作Web服务器,当我执行phpinfo()时;它使用/etc/php5/fpm/php.ini

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

现在在我的php代码中,我正在尝试使用以下代码设置文件上传大小和最大文件上传数量.

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');

但是当我执行ini_get('max_file_uploads')并回显该值时,它显示的默认值为20,实际上,我无法在运行时使用ini_set()更改任何ini值.

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().

关于如何在运行时使用php代码更改这些值的任何想法?

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

谢谢.

推荐答案

并非所有的PHP ini指令都可以在运行时更改(通过ini_set).请参阅PHP手册和定义可更改性值,即PHP_INI_SYSTEM和PHP_INI_PERDIR作为您所需的设置,但都不能在运行时进行设置.

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.

要仅在应用的一部分中获得这些设置,您可能需要妥协并在php.ini文件中全局设置max_file_uploads设置(因为它是PHP_INI_SYSTEM),然后使用您喜欢的按目录配置机制(.htaccess, .user.ini(> 5.3)等)为您应用的特定部分设置upload_max_filesize. 参见此处以获取良好的说明.

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.

这篇关于如何/不能使用ini_set()方法在运行时设置php.ini值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:48