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