-2

I want to get the file upload control file size using jquery. How i can do it .. Can any one help me. I am using MVC 3

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150

2 Answers2

0

At least search the site before posting a question. However Here is a good answer to get the file size. Determining image file size + dimensions via Javascript?

However, if you want the extension of a file to validate the user input, you can try the following

    $(document).ready(function () {
    $("#uploadImage").live("change", function () {
    alert(this.files[0].size); // this line will return the file size 
        var file = $('#uploadImage').val().split('.').pop().toLowerCase();

        if ($.inArray(file, ['gif', 'png', 'jpg', 'jpeg', 'tif', 'bmp', 'doc', 'docx', 'pdf', 'xlsx', 'xls', 'txt']) == -1) {
            alert('Only file with extension ".jpg", ".jpeg" , ".png" , ".gif", ".tif", ".bmp",".doc",".docx",".pdf",".xlsx",".xls",".txt" are allowed');
        }
    });
}); 

Note: files[0].size is a html 5 api property. So it may not work in all browser.

Community
  • 1
  • 1
0

I made a plugin right for this thing. but be aware, it's a control only client-side, you should check the file size in you server too

anyway, this is the plugin (require jquery): contro file size v. 1.30

Nereo Costacurta
  • 7,693
  • 4
  • 21
  • 27