gatzkerob Posted May 27, 2011 Share Posted May 27, 2011 When I try to upload a file larger than the server's max limit, the following code is not executed. How am I supposed to inform the user that their file is too large? NOTE: I've stripped the code down for this post. <?php if(isset($_POST['submit'])) { echo "test.."; } ?> <html> <head> <title>Upload Test</title> </head> <body> <form action='' enctype='multipart/form-data' method='POST'> <input type='file' name='file_upload' /> <input type='submit' name='submit' value='upload' /> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/237641-code-not-executed-when-file-too-large/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. For an upload, you generally test if $_SERVER['REQUEST_METHOD'] == 'POST' to detect that a form was submitted, then you test if the $_FILES array is empty, which would indicate that the size exceeded the post_max_size setting. Then if the $_FILES array is not empty, you would test $_FILES['file_upload']['error'] for any of the other possible upload errors. Link to comment https://forums.phpfreaks.com/topic/237641-code-not-executed-when-file-too-large/#findComment-1221134 Share on other sites More sharing options...
kumarkiranm Posted May 27, 2011 Share Posted May 27, 2011 Using $_SERVER['CONTENT_LENGTH'] you can check the posted file size, even if upload fails. And you can inform the user. check this url http://php.net/manual/en/features.file-upload.php Link to comment https://forums.phpfreaks.com/topic/237641-code-not-executed-when-file-too-large/#findComment-1221141 Share on other sites More sharing options...
gatzkerob Posted May 27, 2011 Author Share Posted May 27, 2011 If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty. For an upload, you generally test if $_SERVER['REQUEST_METHOD'] == 'POST' to detect that a form was submitted, then you test if the $_FILES array is empty, which would indicate that the size exceeded the post_max_size setting. Then if the $_FILES array is not empty, you would test $_FILES['file_upload']['error'] for any of the other possible upload errors. Thanks, I was just about to ask how on earth I'm supposed to use UPLOAD_ERR_INI_SIZE or UPLOAD_ERR_FORM_SIZE when $_FILES is empty due to an over-sized file (paradox?). Then kumarkiranm came up with an answer. Link to comment https://forums.phpfreaks.com/topic/237641-code-not-executed-when-file-too-large/#findComment-1221145 Share on other sites More sharing options...
gatzkerob Posted May 27, 2011 Author Share Posted May 27, 2011 Using $_SERVER['CONTENT_LENGTH'] you can check the posted file size, even if upload fails. And you can inform the user. check this url http://php.net/manual/en/features.file-upload.php Just what I was looking for. Thank you. Link to comment https://forums.phpfreaks.com/topic/237641-code-not-executed-when-file-too-large/#findComment-1221147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.