Jump to content

Recommended Posts

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

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.