客户端:
var logofile = form.logofile.value;
if(trim(form.name.value)!=""){
var ext = logofile.substring(logofile.length-3).toLowerCase();
if(ext != "jpg"&&ext != "gif"&& ext != "bmp" &&ext != "png"){
alert("只允许上传gif、bmp、jpg、png格式的文件");
return false;
}
}
服务端:
public static boolean validateFileType(FormFile formFile){
if(formFile != null && formFile.getFileSize()>0){
List<String> arrowType = Arrays.asList("image/bmp","image/jpg","image/png","image/gif","image/jpeg"
,"image/pjpeg");
return arrowType.contains(formFile.getContentType().toLowerCase());
}
return true;
}