/ Published in: JavaScript
Get file size from javascript code
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function validateFileSize(component,maxSize,msg){ if(navigator.appName=="Microsoft Internet Explorer"){ if(component.value){ var myFSO = new ActiveXObject("Scripting.FileSystemObject"); var filepath = component.value; var thefile = myFSO.getFile(filepath); var size = thefile.size; } } else { if(component.files[0]!=''){ size = component.files[0].size; } } if(size!='' && size>maxSize){ jAlert('Upload file size should be less than 25MB.','document.theform.uploadbroucher','uploadbroucher'); document.getElementById('uploadbroucher').value=""; return false; } else { return true; } } component - document.getElementById('filed')