ini_get('post_max_size')
can (and will) return human-friendly values. So you will end up comparing integer file size values with string values (8M
in your case). And 9000 > '8M'
...
UPDATE:
There is no need to explicitly use the PHP configuration values post_max_size
or upload_max_filesize
, because:
- in case of exceeding the
post_max_size
value, the $_FILES
array will be empty, plus a warning will be generated, e.g.:
Warning: POST Content-Length of 3414 bytes exceeds the limit of 2048 bytes in Unknown on line 0
- in case of exceeding the
upload_max_filesize
value, the corresponding 'error'
field(s) within the $_FILES
array will contain the UPLOAD_ERR_INI_SIZE
value, e.g:
array(1) { ["name"]=> array(5) { ["name"]=> string(12) "filename.ext" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(1) ["size"]=> int(0) } }
All the above mean that if there's a non-empty $_FILES
array available and the value of the error field is UPLOAD_ERR_OK
, you can be sure that the upload was successful and configuration values were also respected.
In your case this translates to the condition if ($_FILES['file']['size'] <= ini_get('post_max_size')) ...
not only incorrect (comparing integer file sizes (e.g. 9000
) with possibly non-integer strings (e.g. '8M'
)), but also not needed at all.