php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #41977 A feature to detect post_max_size exceeded (plus friends)
Submitted: 2007-07-12 15:39 UTC Modified: -
Votes:6
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mikko dot rantalainen at peda dot net Assigned:
Status: Open Package: Feature/Change Request
PHP Version: 5CVS-2007-07-12 (CVS) OS: Ubuntu Linux 6.06
Private report: No CVE-ID: None
 [2007-07-12 15:39 UTC] mikko dot rantalainen at peda dot net
Description:
------------
As described in http://php.net/manual/en/ini.core.php#ini.post-max-size if the POST data is greater than post_max_size, then both $_POST and $_FILES are empty. The documentation shows a way using the $_GET array as a workaround to detect the situation. However, such workaround cannot be always used because script author may not be the author of the original form and as such cannot add any GET parameters to said form. A method to identify the situation where the user has exceeded post_max_size is therefore required.

I'm suggesting a generic solution:

Add function get_server_status()

This function returns an integer which is a sum (bit mask) of following constants

/** HTTP input has or had GET parameters */
SERVER_STATUS_HAD_GET_DATA 1
/** HTTP input has or had POST data */
SERVER_STATUS_HAD_POST_DATA 2
/** HTTP input has or had uploaded files */
SERVER_STATUS_HAD_FILES 4
/** post_max_size was exceeded, $_POST and $_FILES are empty */
SERVER_STATUS_POST_MAX_SIZE_TRIGGERED 8
/** max_filesize was exceeded */
SERVER_STATUS_UPLOAD_MAX_FILESIZE_TRIGGERED 16
/** memory_limit was exceeded before start of the script */
SERVER_STATUS_MEMORY_LIMIT_TRIGGERED 32
/** max_input_time exceeded before start of the script */
SERVER_STATUS_MAX_INPUT_TIME_TRIGGERED 64

This way a script could also handle the case there memory_limit was hit because the uploaded file was too big (at least older versions of PHP required at least as much memory as the size of the upload). However, because the memory space that was not enough for file upload is now free to use for PHP, the script should be able to handle the situation using that same memory (e.g. tell the user about the issue in a nice way or redirect to alternative method).

Note that I've named the function get_server_status() instead of get_input_status() or get_http_input_status() so that this same function can be extended in the future for other server/php host status.

Feel free to drop constants/situations that cannot be handled by the script, they are of no use in any case.



Patches

Pull Requests

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 13:01:27 2024 UTC