Home > Article > Backend Development > How Do PHP\'s `post_max_size` and `upload_max_filesize` Work Together for File Uploads?
Understanding PHP File Upload Size Limits
The PHP configuration settings post_max_size and upload_max_filesize play crucial roles in handling file uploads. However, their interaction can be confusing.
The Confusion
In the provided example, post_max_size is set to 8Mb, while upload_max_filesize is set to 16Mb. Logically, one might assume that files up to 16Mb could be uploaded. However, the smaller post_max_size limit overrides this assumption, resulting in errors when attempting to upload files larger than 8Mb.
Definition of Limits
Interaction of Limits
post_max_size acts as a total limit on the combined size of all files and other data being submitted via POST. This means that even if upload_max_filesize allows for larger files, the overall request size must adhere to post_max_size.
Solution for Large File Uploads
To allow for the upload of files larger than post_max_size, one needs to find an alternative way to transmit the file without using POST. This could involve:
Error Detection
When post_max_size is exceeded, $_POST and $_FILES will be empty. However, $_SERVER['CONTENT_LENGTH'] will be greater than 0. It's important to note that if no post variables or files are transmitted, $_SERVER['CONTENT_LENGTH'] will be 0.
The above is the detailed content of How Do PHP\'s `post_max_size` and `upload_max_filesize` Work Together for File Uploads?. For more information, please follow other related articles on the PHP Chinese website!