Get Size of Post-Request in PHP

What is the size limit of a post request?

It depends on a server configuration. If you're working with PHP under Linux or similar, you can control it using .htaccess configuration file, like so:

#set max post size
php_value post_max_size 20M

And, yes, I can personally attest to the fact that this works :)

If you're using IIS, I don't have any idea how you'd set this particular value.

Get byte size of http request in PHP

I found out that the best way for getting this for my use is by using:

$size = @file_get_contents('php://input');

Thanks for the help guys!

Check sent $_POST size

If you are trying to measure the size of the request, the $_SERVER superglobal has a property for this.

  $size = (int)$_SERVER['CONTENT_LENGTH'];

Submit your post to an endpoint with this code and echo it's value.

This will assign the value of the Content-length HTTP header to $size if the request was sent via the POST method.

How can I check the POST data size before I submit it with jQuery?

You can estimate it by counting the length of your serialized form, excluding file upload fields. So it would be somewhere along these lines:

$("form").not("[type='file']").serialize().length;

How to get php://input size?

php://input is not a file, so fstat() doesn't have anything to process.

So, yes, you are going to have to special-case php://input



Related Topics



Leave a reply



Submit