Getting the maximum upload size in PHP

There’s been a few times where I’ve needed to display the maximum size of a file that can be uploaded, but there never seemed to be an easy way to do it. Well, there’s still not, but at least this will give you the right value.

The code that you need to use is:
$upload_mb = min((int) ini_get ("upload_max_filesize"), (int) ini_get ("post_max_size"), (int) ini_get ("memory_limit"));

What we are doing here is checking for the lowest of the three values that determine the upload limits: file upload size, POST size and memory limit. We use the lowest of these values to determine just what we can upload.

Leave a Reply

Your email address will not be published. Required fields are marked *