Oleksandr IY
Oleksandr IY

Reputation: 3106

ini_set doesn't overwrite php settings

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?

Upvotes: 2

Views: 2307

Answers (3)

dader
dader

Reputation: 1314

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 !

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798456

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.

Upvotes: 1

mario
mario

Reputation: 145472

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.

Upvotes: 4

Related Questions