Jump to content

code not executed when file too large


gatzkerob

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.