Monday, 26 November 2018

Get input type file size in KB


HTML

<input type="file" class="upload" onchange="readURL(this)" id="file" accept="image/x-
png,image/jpeg" />

<input type="button" value="Upload" class="btn btn-default" style="margin:auto;display:block" onclick="UploadPaper()" />

Java Script


function UploadPaper()
{
    ValidatePaper();

    if (Flag) {
     
        checksize('file');
    }
}
// check file size
function checksize(file) {
  
    var size = $j("#" + file)[0].files[0].size / 1024;
   
    if (size>100) {
       alert("File size exceed. Maximum 100kb is allowed.");
        return false;
    }
    else {
       alert("ok");
        return true;
    }
   
}