How to the change php settings from php code?

2019-02-20 20:27发布

I want to change the php setting but from ".php" page not php.ini. The settings I want to change is

upload_max_filesize, post_max_size and memory_limit

标签: php settings
4条回答
神经病院院长
2楼-- · 2019-02-20 20:31

The only one of those that can be changed from within PHP is the last one, which can be changed with ini_set like this:

ini_set('memory_limit', '32M');

PHP always processes the client request before the PHP script is started. This means that uploaded files are already uploaded and posted forms are already fully posted beforeb he script starts. The upload and post settings can therefore not be set in the script, ebcause they are already irrelevant when the PHP script is started.

查看更多
三岁会撩人
3楼-- · 2019-02-20 20:38

Use

ini_set ('key', 'value');

Note that not all the available options can be changed using ini_set(). Here'is a list: ini.list

Read more in ini_set reference;

查看更多
在下西门庆
4楼-- · 2019-02-20 20:39

If your server administrator hasn't prevented it, you can use ini_set() to change the memory limit:

ini_set("memory_limit","16000000"); // abbreviations like "16M" work only 
                                    // in php.ini, always use full numbers here

The two other options are needed before the PHP script is loaded, there is no way to change those in php.ini.

查看更多
Anthone
5楼-- · 2019-02-20 20:46

You can try it with a .htaccess file, if you have AllowOverride Options:

Place a file named .htaccess to your webroot:

php_value upload_max_filesize 10000
php_value post_max_size 10000
php_value memory_limit 10000
查看更多
登录 后发表回答