JS judge file format and size of a simple example (must SEE) _javascript skills

Source: Internet
Author: User

Examples are as follows:

Determines the photo size
function getphotosize (obj) {
  photoext=obj.value.substr (obj.value.lastIndexOf (".")). toLowerCase ()//Get file suffix name
  if (photoext!= '. jpg ') {
    alert ("Please upload a photo with suffix name jpg!");
    return false;
  }
  var fileSize = 0;
  var Isie =/msie/i.test (navigator.useragent) &&!window.opera;      
  if (Isie &&!obj.files) {     
     var filePath = obj.value;      
     var filesystem = new ActiveXObject ("Scripting.FileSystemObject");  
     var file = Filesystem.getfile (FilePath);        
     fileSize = file. Size;     
  } else { 
     fileSize = obj.files[0].size;   
  } 
  Filesize=math.round (filesize/1024*100)/100; The Unit is KB
  if (filesize>=10) {
    alert ("Photo maximum size is 10KB, please upload it again!");
    return false;
  }
}

JSP page:

<input type= "File" id= "Imgfile name=" upload "style=" width:150px; "onchange=" getphotosize (this)/>

The above is small series for everyone to bring the JS judge file format and size of a simple example (must see) all the content, I hope that we support cloud Habitat Community ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.