Posted By

satinfo30 on 12/03/12


Tagged


Versions (?)

file size from javascript


 / Published in: JavaScript
 

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

Get file size from javascript code

  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')

Report this snippet  

You need to login to post a comment.