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?
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.
Related
I am using a prestashop and I need to change the max_input_vars so translation changes are applied from the Translation section.
I cannot use php_value in .htaccess because of my hosting provider policy, so I need to use the php.ini file.
I've created it into the prestashop administration folder with the content:
max_input_vars = 3000
But when I update the translations, I get the error of max_input_vars, so it is not being changed with the php.ini. I've also tried without blanks, with a trailing ";" and no effect.
To check it, I've created a file with just phpinfo() and it tells me that it is set to 1000 (the default value).
I supposed that using ini_set just above the phpinfo call would change its value (only for that script), but in fact, it does not change anything.
So, I put:
ini_set("max_input_vars","3000");
phpinfo();
and the value I am getting for max_input_vars is 1000.
Any idea on how to change the value, or why it is not working?
This configuration setting is not settable at runtime from code. If you look at the list of configuration settings you will see that its "changeable" value is PHP_INI_PERDIR. This page explains what that means.
ini_set can only affect settings that are marked changeable as PHP_INI_USER.
The logical explanation for this is that the setting affects PHP's behavior before your code has had a chance to run.
The setting applies while PHP is trying to parse the data sent to the script. This happens before your script is even executed. So you simply cannot set it at runtime because the setting affects something pre-runtime.
I am trying to change the max_memory parameter so I went into my php.ini and set max_memory = 500M For some reason, when I use phpinfo(), that setting still displays 128M (the default setting). I read that some hosts restrict max_memory. Is there a way to change this value manually, or override this option in a config file, or do I have to recompile php?
If you can recompile PHP, then you, obviously, have full control of the web server.
I would guess, as written in the comments, you:
Did not restart the Apache (or not the right Apache)
(as you found) You are editing the wrong ini file.
Your server simply don't have 500MB free memory
a few other things to check:
the report from phpinfo states that it is using the php.ini file that you're editing, not some more "specific" .ini file somewhere else
you haven't overridden the memory_limit variable through an apache .htaccess file or using ini_set in a PHP script somewhere
if you're in a shared environment, as Itay suggests, you may not have more than 128M available to your account, and you probably don't have access to reset apache either.
if that's the case, try making the value smaller to see if the changes you're making take effect. If they are, and you can't increase it above 128M, time to upgrade your hosting account.. otherwise, try making the change through .htaccess or ini_set in your script because those methods don't require an apache restart.
if you still can't get it to work, contact the host and ask them to make you a local copy of the global php.ini file for your account.
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
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
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.
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.
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;
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
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
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.
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.
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;
I am trying to increase the value of upload_max_filesize to 10485760 (10M).
I am using:
ini_set('upload_max_filesize',10485760);
This is always returning false and the upload_max_filesize continues to be 2M.
I am using php 5.2.8 on windows and I don't have the ini_set disabled and am also not with safe mode on.
Anyone know why this doesn't work?
Thanks
The upload_max_size setting will be checked before your PHP script starts running. So by the time you change the setting, the upload already failed.
Try editing the value in the php.ini file instead of in your PHP script. Your script may not for whatever reason have permissions to override php.ini.
Check variable [post_max_size][1].
Sets max size of post data allowed.
This setting also affects file upload.
Try this:
ini_set('upload_max_filesize','100M');
is it running in apache (mod_php)? if so there are settings in apache that effect this as well.
The apache webserver has a LimitRequestBody configuration directive that restricts the size of all POST data regardless of the web scripting language in use. Some RPM installations sets limit request body to 512Kb. You will need to change this to a larger value or remove the entry altogether.