How to check file input size with jQuery?

前端 未结 8 2438
渐次进展
渐次进展 2020-11-22 09:21

I have a form with file upload capabilities and I would like to be able to have some nice client side error reporting if the file the user is trying to upload is too big, is

8条回答
  •  眼角桃花
    2020-11-22 09:45

    Plese try this:

    var sizeInKB = input.files[0].size/1024; //Normally files are in bytes but for KB divide by 1024 and so on
    var sizeLimit= 30;
    
    if (sizeInKB >= sizeLimit) {
        alert("Max file size 30KB");
        return false;
    }
    

提交回复
热议问题