How to check file input size with jQuery?

前端 未结 8 2416
渐次进展
渐次进展 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 09:33

    Use below to check file's size and clear if it's greater,

        $("input[type='file']").on("change", function () {
         if(this.files[0].size > 2000000) {
           alert("Please upload file less than 2MB. Thanks!!");
           $(this).val('');
         }
        });
    

提交回复
热议问题