file size from javascript


/ Published in: JavaScript
Save to your folder(s)

Get file size from javascript code


Copy this code and paste it in your HTML
  1. function validateFileSize(component,maxSize,msg){
  2. if(navigator.appName=="Microsoft Internet Explorer"){
  3. if(component.value){
  4. var myFSO = new ActiveXObject("Scripting.FileSystemObject");
  5. var filepath = component.value;
  6. var thefile = myFSO.getFile(filepath);
  7. var size = thefile.size;
  8. }
  9. } else {
  10. if(component.files[0]!=''){
  11. size = component.files[0].size;
  12. }
  13. }
  14. if(size!='' && size>maxSize){
  15. jAlert('Upload file size should be less than 25MB.','document.theform.uploadbroucher','uploadbroucher');
  16. document.getElementById('uploadbroucher').value="";
  17. return false;
  18. } else {
  19. return true;
  20. }
  21. }
  22.  
  23.  
  24. component - document.getElementById('filed')

URL: http://deepeshdarshan.wordpress.com/2012/06/20/how-to-validate-upload-file-size-and-file-extension-using-javascript/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.