JS judge upload file size __js

Source: Internet
Author: User
JS code   

Find information on your own online   and test   file upload size limit An example, compatible Ie6,ie7,ie8 ,google chrome,ff and other browsers, IE8 above the security settings at the set up a bit better (tools => Internet Options => Security => Internet => Custom Level     Find "include local directory path when uploading files to server", set to Enabled).

JS Code    function filechange (target,id)  {               var fileSize = 0;                    if  (Isie && !target.files)  {                      var filePath = target.value;                     var fileSystem = new  ActiveXObject ("Scripting.FileSystemObject");                                    if (!filesystem.fileexists (FilePath)) {             &nBsp;       alert ("Attachment does not exist, please re-enter it.") ");                     var file=document.getelementbyid (ID);                      file.outerHTML=file.outerHTML;                    return;                  }                 var file =  filesystem.getfile  (FilePath);                  filesize = file. size;              } else {                     filesize =  target.files[0].size;            }                          var size = fileSize / 1024;               if (size>100000) {                  alert ("attachment size cannot be greater than 100M.) ");                 var  File=document.getelementbyid (ID);                  file.outerHTML=file.outerHTML            }           &nbsP; if (size<=0) {                Alert ("Attachment size cannot be 0M.) ");                var file= document.getElementById (ID);                  file.outerHTML=file.outerHTML           }          }   

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.