Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check file-size using jQuery without uploading file

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 601
    Comment on it

    A simple code snippet for checking the file-size of a file before uploading it. It will not only help to save time but also network resource as we can implement the file check at the initial point only.

    The current code allows the user to select a file and then it shows an alert showing the file-size of the file after selection. The code utilizes jQuery to find the file-size.

    <!DOCTYPE HTML>
    <html>
    <head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    </head> 
    <body>
    <form action="upload" enctype="multipart/form-data" method="post">
    
    Upload File:
    <input id="filesize" type="file" name="file" />
    <input type="submit" value="Upload" />
    
    <script type="text/javascript">
        $('#filesize').bind('change', function() {
            alert('This file size is: ' + this.files[0].size/1024/1024 + "MB");
        });
    </script>
    </form>
    </body>
    </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: