puzhibing
6 天以前 082bddee7df8a05ca95f473ec2643701d41a5213
ruoyi-common/src/main/java/com/ruoyi/common/core/controller/FileController.java
@@ -13,6 +13,7 @@
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
 * 文件上传控制类
@@ -48,6 +49,10 @@
        }
        // 获取文件名称
        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++) {
@@ -56,9 +61,10 @@
        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);//目标文件