Upload Attachment Verification method

Source: Internet
Author: User

<inputtype= "File"value= "Select Picture"name= "Accountlicence"onchange= "Filechange (this, ' pic ')"class= "Inputtext selectbtn"><inputtype= "File"value= "Select Attachment"name= "Accountlicence"onchange= "Filechange (this, ' Doc ')"class= "Inputtext selectbtn">

Before the verification of the method of uploading attachments, simple display, although not perfect but also can use, the back will be set to write a form operation of the plug-in, finishing in ~


functionFilechange (target,docpic) {varFileSize = 0; varFilePath =Target.value; varAGT =window.navigator.userAgent; varIsie = Agt.tolowercase (). IndexOf ("MSIE")! =-1; if(Isie &&!)target.files) {varFileSystem =NewActiveXObject ("Scripting.FileSystemObject"); if(!filesystem.fileexists (FilePath)) {Dialog.alert ("The attachment does not exist, please re-enter!" "); return; } varFile =Filesystem.getfile (FilePath); FileSize=file. Size; } Else{fileSize= Target.files[0].size; } varSize = filesize/1024; if(docpic== "Doc" &&size>4000) {Dialog.alert ("Attachment size cannot be greater than 4m! ",function() {Target.value=""; }); } if(docpic== "pic" &&size>2000) {Dialog.alert ("Attachment size cannot be greater than 2m! ",function() {Target.value=""; }); } if(size<=0) {Dialog.alert ("The attachment size cannot be 0m! ",function() {Target.value=""; }); } //Get upload file name varFilearr=filepath.split ("\ \"); varFiletarr=filearr[filearr.length-1].tolowercase (). Split ("."); varFiletype=filetarr[filetarr.length-1]; //cut out suffix file name if(docpic== "pic" &&size<2000&&filetype! = "JPG" &&filetype! = "JPEG" &&filetype! = " GIF "&&filetype! =" png "&&filetype! =" BMP ") {Dialog.alert ("File type error!<br/> Please select" jpg/jpeg/gif/png/bmp "type",function() {Target.value=""; }); } if(docpic== "Doc" &&size<4000&&filetype! = "Doc" &&filetype! = "Docx" &&filetype! = " XLS "&&filetype! =" xlsx "&&filetype! =" PDF ") {Dialog.alert ("File type error!<br/> Please select" doc/docx/xls/xlsx/pdf "type",function() {Target.value=""; }); } }


Upload Attachment Verification method

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.