Correct upload limit in PHP to work with Cloudflare's upload limit

In the PHP config are 3 variables which are important for the upload:
memory_limit
post_max_size
upload_max_filesize
where memory_limit has to be larger than post_max_size and upload_max_filesize
and
where post_max_size has to be larger than upload_max_filesize

memory_limit is usually set to 256M in my environments, so that’s way over the limit and nothing to worry about.

However, the problem lies with post_max_size and upload_max_filesize. The question is, which of these two variables have to be 100M, to comply with Cloudflare’s upload limit?

Is it

post_max_size = 100M
upload_max_filesize = 99M

or

post_max_size = 101M
upload_max_filesize = 100M

Thank you for you help :slight_smile:

You don’t have to comply with CF’s upload limit, CF will simply kill requests that send more than 100mb in the request body. But, if you do just want to allow the max upload that CF allows, you can set both of those variables at or above 100mb.

I could just make both 100M, but to which of these 2 does the upload limit apply to? The post_max_size which includes everything or upload_max_filesize which only includes the files?

post_max_size

Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize.

upload_max_filesize

The maximum size of an uploaded file.

Upload limit applies to both. The upload_max_filesize is a per-file size limit, so if you set it to 20mb or 19mb you could upload 5 files per POST request, or you could set it to 100mb and post_max_size to 101mb to upload 100mb files.

2 Likes

Oh boi, great answer, also just learned something new. Thanks :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.