Layui file type and size before upload callback

Source: Internet
Author: User

1. About Layui.upload before before uploading to the file type and file size judgment, block the default upload implementation method "Code is the image upload is wide and high limit processing":

Layui.use ([' Upload ', ' form '),function () {            varUpload =Layui.upload; varform =Layui.form; Upload.render ({elem:' #uploadCover ', URL:'/file/upload.shtml ', Method:"POST", Auto:false//auto parameter must be set to False, Size:"2048", Accept:"File", exts:' Jpg|png|jpeg ', choose:function(obj) { //Pre-Upload Select callback method varFlag =true; Obj.preview (function(index, file, result) {console.log (file); File represents the document information, and result indicates the file src addressvarIMG =NewImage (); IMG.SRC=result; Img.onload=function() {///Initial folder after completion of the upload image to obtain the width of high, to determine the limit of the size of the uploaded image. if(Img.width ==343 && img.height ==240{obj.upload (index, file);//Meet Conditional Call upload method}Else{flag=false; D.msg ("The size of your uploaded thumbnail must be 343*240 size!" "); return false; }                        }                        returnFlag;                }); }, Done:function(res) {// upload Successful callback method $ ("#xcCoverUrl"). Val (Res.data); $("#xcCoverUrlShow"). attr ("src", Res.fastdfshost +res.data); Layer.closeall (' Loading ');        }            }); });

Layui file type and size before upload callback

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.