ETA: some have suggested ini_set()
but it's my understanding this is a server-side setting; I need per-script independence at run-time. E.g., three scripts simultaneously running like this: x.php uses 2k, y.php uses 4k, and z.php uses 8k.
How do I programmatically set a limit on the POST max size on a per-script basis (i.e., not server-wide)?
For instance in Perl one would simply do this in each script, thus allowing each one to set its own limit at run-time:
# The $POST_MAX variable also applies to the combined size of all the elements
# in a form. Therefore, you can set this variable to keep people from pasting
# huge amounts of junk into text fields, too.
$CGI::POST_MAX = 1024 * 2;
I realize there is a setting in php.ini to limit the maximum POST size for all PHP scripts:
; Maximum size of POST data that PHP will accept.
; http://php.net/post-max-size
post_max_size = 8M
But I want to know how to do this on a per-script basis (because each script will have its own limits).
Note: Presumably one can set a limit in Apache httpd.conf and/or in a .htaccess but I do not want to do this.
post_max_size is the maximum size for all POST body data. It doesn't matter if you're POSTing JSON or your DVD collection, this is all POST body data. Your file upload counts towards this limit.
To increaes file upload size in PHP, you need to modify the upload_max_filesize and post_max_size variable's in your php. ini file. In addition, you can also set the maximum number of files allowed to be uploaded simultaneously, in a single request, using the max_file_uploads .
The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.
Specifically, you may be directed to edit a file on your server called php.ini, and to increase the post_max_size limit. post_max_size is a setting managed through the PHP Options which sets the maximum size of POST data that PHP will accept. This value should be at least as big as upload_max_filesize.
# The $POST_MAX variable also applies to the combined size of all the elements # in a form. Therefore, you can set this variable to keep people from pasting # huge amounts of junk into text fields, too. $CGI::POST_MAX = 1024 * 2; I realize there is a setting in php.ini to limit the maximum POST size for all PHP scripts:
All ChemiCloud customers should see the Select PHP Version section in their hosting account’s cPanel. 3) In the new window click on the Switch To PHP Options button. 4) Here you can locate the post_max_size and click on the value. A dropdown menu or text input box will appear, allowing you to change the value as required.
For instance in Perl one would simply do this in each script, thus allowing each one to set its own limit at run-time: # The $POST_MAX variable also applies to the combined size of all the elements # in a form. Therefore, you can set this variable to keep people from pasting # huge amounts of junk into text fields, too. $CGI::POST_MAX = 1024 * 2;
use ini_set
and then set your php setting as you like.
Example
ini_set('upload_max_filesize', '60M');
ini_set('max_execution_time', '999');
ini_set('memory_limit', '128M');
ini_set('post_max_size', '60M');
To change the ini settings on per script basis you can use:
ini_set('post_max_size', '10M')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With