ini_set不会覆盖php设置

问题描述:

I am trying upload larger files so I set this in php code

    ini_set('upload_max_filesize', '1000M');
ini_set('post_max_size', '1100M');
ini_set('memory_limit', '1200M');

but $_POST and $_FILES are empty. But when I change php.ini settings it works. Why it doesn't change setting on the fly?

我正在尝试上传更大的文件,所以我在php代码中设置了这个 p>

   ini_set('upload_max_filesize','1000M'); 
ini_set('post_max_size','1100M'); 
ini_set('memory_limit','1200M'); 
  code>  pre> 
  
 

但$ _POST和$ _FILES为空。 但是,当我更改php.ini设置时,它的工作原理。 为什么它不会动态改变设置? p> div>

It's too late to have those settings changed after PHP has started.

  • upload_max_filesize - uploads happen before the PHP script runs and your ini_set() is executed
  • post_max_size - likewise

And even if you could change memory_limit (depends on server configuration), it would be too late again if you expect that big of an upload.

See ini_set() and http://www.php.net/manual/en/ini.list.php for more info.

Have a look at these :

http://www.php.net/manual/en/ini.list.php

http://www.php.net/manual/en/configuration.changes.modes.php

After reading, it seems that the only option that you can modify with ini_set is memory_limit. The others 2 being configurable in the php.ini file, in httpd.conf, .htaccess, or in a per directory .user.ini file.

Meaning, if you want to change these values, you must have access to your server's configuration ! You won't be able to afford that from within the script !

The first two settings are not allowed to be changed per script, but even if they were it still would not be effective since the files/POST data must be handled before the script is even run, which means that the settings wouldn't have a chance to take effect.