I am sending data to PHP through HTTP POST. This works fine for data shorter than 8MB (8192KB), however when higher quantities of data are sent, PHP shows the $_POST variable to be empty. I emphasize that the $_POST variable does not even contain the names of the post fields, it exists as an empty array. The critical point seems to be between 8.0MB and 9.0MB, and continues higher of course.
I have attempted the following with no success:
ini_set('memory_limit', '500M');
ini_set('post_max_size', '220M');
ini_set('upload_max_filesize', '220M');
I require the data to pass through HTTP POST. The data cannot be uploaded as a file.
Also could Apache be responsible for this?
Any help would be appreciated.
This will help
What are the caveats with increasing max_post_size and upload_max_filesize?
And maybe
http://blurringexistence.net/archives/11-PHPs-max_post_size.html
take a look at the documentation comments. when the script is executed, itäs too late to change sopme setting, wich includes post_max_size, for example. to change these values, try to use a .htaccess-file like this:
php_value upload_max_filesize 200M
php_value post_max_size 200M
or change these settings directly in your php.ini.
post_max_size is, according to the documentation, defined as a PHP_INI_PERDIR setting. It can be set in your php.ini or .htaccess file. A definition for PHP_INI_PERDIR is given here: http://www.php.net/manual/en/configuration.changes.modes.php
Settings that are defined as PHP_INI_ALL can be set with ini_set().
Related
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.
I am having a strange problem while uploading large files in PHP.
In php.ini, max_execution_time is set to 30, post_max_size is set to 32M, upload_max_filesize is set to 32M. When I tried to upload a file of size 40.2 MB, it don't show any error. The $_FILES variable has the value array(0) { } and $_FILES['userfile'] shows NULL.
If the file size is more than the value set in php.ini, then it should return the error message
UPLOAD_ERR_INI_SIZE, Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
But it's not showing any error either (as $_FILES is an empty array). I am clueless why this is happening.
When I change in php.ini and set post_max_size is set to 64M, upload_max_filesize is set to 64M, then it works fine. So, I decided to use the following code, instead of changing php.ini file.
ini_set('upload_max_filesize', '64M');
ini_set('post_max_size', '64M');
ini_set('max_execution_time', 300);
I even tried to increase max_execution_time. Still, I am having the same problem. ini_set() is not working here.
To have the 40 MB file fail with upload error, you have to increase the post_max_size, if you exceed the value of that variable, you get an empty $_FILES array. See the manual
If the size of post data is greater
than post_max_size, the $_POST and
$_FILES superglobals are empty.
Also, ini_set() is not working there because two of the variables you are trying to change are PHP_INI_PERDIR and thus need to be changed in php.ini or in .htaccess or httpd.conf. You should try the 40MB file with, for example, these settings in .htaccess
php_value upload_max_filesize 32M
php_value post_max_size 64M
php_value max_execution_time 300
There is one more setting you may need to look at, Apache's LimitRequestBody.
If the file exceeds that, the upload may get blocked before it even reaches PHP.
Apache Documentation
ini_set() is not working here.
The values you are trying to change with ini_set(), except for max_execution_time, cannot be changed with ini_set().
In the list of php.ini directives, they are reported to be of type PHP_INI_PERDIR, which means (as explained in Where a configuration setting may be set) that they can changed in php.ini, .htaccess or httpd.conf. Configuration settings that can be changed with ini_set() are the ones marked as PHP_INI_USER.
FOR SERVER:
In cPanel search for php, You will find "Select PHP version" under Software.
Software -> Select PHP Version -> Switch to Php Options -> Change Value -> save.
FOR LOCAL:
Find the PHP ini(configuration settings) file in php folder under xampp.
Change
post_max_size = 40M and upload_max_filesize = 40M
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.