| | |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.Locale; |
| | | |
| | | /** |
| | | * 文件上传控制类 |
| | |
| | | } |
| | | // 获取文件名称 |
| | | String filename = mf.getOriginalFilename(); |
| | | if (filename == null || !filename.contains(".")) { |
| | | return AjaxResult.error("上传文件缺少扩展名!"); |
| | | } |
| | | filename = new File(filename).getName(); |
| | | // 生成随机5位英文字母 |
| | | String rename = ""; |
| | | for (int i = 0; i < 5; i++) { |
| | |
| | | long l = System.currentTimeMillis(); |
| | | // 获取文件后缀 |
| | | String temp = rename+l+filename; |
| | | String ext = temp.substring(temp.lastIndexOf("."), temp.length()); |
| | | String ext = temp.substring(temp.lastIndexOf(".")).toLowerCase(Locale.ROOT); |
| | | // 检查文件类型 |
| | | if (!fileUploadConfig.getAllowExt().contains(ext)) { |
| | | String allowExt = fileUploadConfig.getAllowExt().toLowerCase(Locale.ROOT); |
| | | if (!allowExt.contains(ext)) { |
| | | return AjaxResult.error("上传文件格式不正确,仅支持" + fileUploadConfig.getAllowExt()); |
| | | } |
| | | File targetFile = new File(realPath, temp);//目标文件 |