JavaScript file upload size validation

后端 未结 13 2175
眼角桃花
眼角桃花 2020-11-22 00:23

Is there any way to check file size before uploading it using JavaScript?

13条回答
  •  悲哀的现实
    2020-11-22 01:15

    I made something like that:

    $('#image-file').on('change', function() {
     var numb = $(this)[0].files[0].size/1024/1024;
    numb = numb.toFixed(2);
    if(numb > 2){
    alert('to big, maximum is 2MB. You file size is: ' + numb +' MB');
    } else {
    alert('it okey, your file has ' + numb + 'MB')
    }
            });
    
    

提交回复
热议问题