SoFunction
Updated on 2025-03-01

Simple examples of js judging file format and size (must read)

Examples are as follows:

//Judge the size of the photofunction getPhotoSize(obj){
  photoExt=((".")).toLowerCase();//Get the file suffix name  if(photoExt!='.jpg'){
    alert("Please upload a photo with the suffix jpg!");
    return false;
  }
  var fileSize = 0;
  var isIE = /msie/() && !;      
  if (isIE && !) {     
     var filePath = ;      
     var fileSystem = new ActiveXObject("");  
     var file =  (filePath);        
     fileSize = ;     
  }else { 
     fileSize = [0].size;   
  } 
  fileSize=(fileSize/1024*100)/100; //The unit is KB  if(fileSize>=10){
    alert("The maximum size of the photo is 10KB, please upload it again!");
    return false;
  }
}

jsp page:

<input type="file"  name="upload" style="width:150px;" onchange="getPhotoSize(this)"/>

The above is the full content of the simple example (must-read) of JS judging file format and size brought to you by the editor. I hope everyone supports me~