Handle PHP upload size limits gracefully - #27
Merged
Merged
Conversation
Detect requests above post_max_size (empty $_POST and $_FILES) before the CSRF check and answer 413 with the limit; show the limit for files above upload_max_filesize instead of the generic error. Tests set PHP ini values via the new phpIni server option. INSTALL.md documents the limits. Fixes #18 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ahgn25kLAXMcG4V7N6s6u9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve handling of file uploads that exceed PHP's
upload_max_filesizeandpost_max_sizelimits by detecting these conditions and showing user-friendly error messages instead of generic security token errors.Changes
index.phpto detect when POST requests exceedpost_max_size(indicated by missing$_POSTand$_FILESdespite non-zeroCONTENT_LENGTH), returning HTTP 413 with a clear message naming the limitUPLOAD_ERR_INI_SIZEandUPLOAD_ERR_FORM_SIZEPHP upload errors, showing a message with theupload_max_filesizelimitINSTALL.mdexplaining PHP upload limits and how to configure web server limits (nginxclient_max_body_size, ApacheLimitRequestBody) to work togetherAppServerto support setting PHP ini values viaphpInioption in server configurationUploadSizeLimitTestwith four test cases covering:upload_max_filesize(40K limit)post_max_size(100K limit)Implementation details
The solution distinguishes between two size limit scenarios:
upload_max_filesize): PHP sets$_FILES['userfile']['error']toUPLOAD_ERR_INI_SIZEorUPLOAD_ERR_FORM_SIZEpost_max_size): PHP discards the entire request body, leaving$_POSTand$_FILESempty despiteCONTENT_LENGTHbeing setBoth cases now provide specific, actionable error messages to users rather than confusing them with security token errors.
https://claude.ai/code/session_01Ahgn25kLAXMcG4V7N6s6u9