Checking File Size Berfore Uploading (Alert File Name & Size)

<!-------------Form---------------->
<input type="file" value="" id="i_file" />
<input type="button" value="Submit" id="i_submit" />
 
 
<!---------------Script---------------------->

$('#i_submit').click( function() {
    //check whether browser fully supports all File API
    if (window.File && window.FileReader && window.FileList && window.Blob)
    {
        //get the file size and file type from file input field
        var fsize = $('#i_file')[0].files[0].size;
        var ftype = $('#i_file')[0].files[0].type;
        var fname = $('#i_file')[0].files[0].name;
       
        if(fsize>1048576) //do something if file size more than 1 mb (1048576)
        {
            alert("Type :"+ ftype +" | "+ fsize +" bites\n(File: "+fname+") Too big!");
        }else{
            alert("Type :"+ ftype +" | "+ fsize +" bites\n(File :"+fname+") You are good to go!");
        }
    }else{
        alert("Please upgrade your browser, because your current browser lacks some new features we need!");
    }
});
Previous
Next Post »