How to set script based POST size limit?

ETA: some suggested ini_set() , but I understand that this is a server-side setting; I need runtime independence. For example, three scenarios work simultaneously as follows: x.php uses 2k, y.php uses 4k, and z.php uses 8k.

How to programmatically set a limit on the maximum POST size based on a script (i.e. not on the server)?

For example, in Perl, simply doing this in each script, thereby allowing everyone to set their own limit at runtime:

 # 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 understand that in php.ini there is a parameter that limits 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 based on a script (because each script will have its own limitations).

Note. Presumably, you can set a limit in Apache httpd.conf and / or in .htaccess, but I don't want to do this.

+4
source share
3 answers

use ini_set and then set your php setting as you want.

Example

 ini_set('upload_max_filesize', '60M'); ini_set('max_execution_time', '999'); ini_set('memory_limit', '128M'); ini_set('post_max_size', '60M'); 
+6
source

To change the ini settings based on a script, you can use:

 ini_set('post_max_size', '10M') 
+1
source

also you can do it in your .htaccess file

 php_value upload_max_filesize 30M 

or you can use the ini_set php function, which is almost disabled by the host provider.

 ini_set('upload_max_filesize', '60M'); 
0
source

All Articles