Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set POST size limit on a per-script basis?

Tags:

post

php

max

limit

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.

like image 489
Scavokovich Avatar asked Feb 28 '13 04:02

Scavokovich


People also ask

What is post max size?

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.

How do I change the file size limit in PHP?

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 .

What is the default maximum size of post in PHP INI?

The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.

How do I increase the post_max_size limit in PHP?

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.

How to limit the size of Post Field in a form?

# 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:

How do I change the post_max_size in chemicloud?

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.

How to limit the size of a form field in Perl?

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;


2 Answers

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'); 
like image 133
Dipesh Parmar Avatar answered Oct 05 '22 23:10

Dipesh Parmar


To change the ini settings on per script basis you can use:

ini_set('post_max_size', '10M')
like image 40
alwaysLearn Avatar answered Oct 06 '22 00:10

alwaysLearn