LogUtil.info("-------------------------step.2-------------------------------------");
cgformFtl.setCgformId(cgformId);
cgformFtl.setCgformName(cgformName);
cgformFtl.setFtlStatus(ftlStatus);
UploadFile uploadFile = new UploadFile(request, cgformFtl);
uploadFile.setCusPath("forms");
message = null;
try {
uploadFile.getMultipartRequest().setCharacterEncoding("UTF-8");
MultipartHttpServletRequest multipartRequest = uploadFile
.getMultipartRequest();
String uploadbasepath = uploadFile.getBasePath();// 文件上传根目录
if (uploadbasepath == null) {
uploadbasepath = ResourceUtil.getConfigByName("uploadpath");
}
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 文件数据库保存路径
String path = uploadbasepath + "\\";// 文件保存在硬盘的相对路径
String realPath = uploadFile.getMultipartRequest().getSession()
.getServletContext().getRealPath("\\")
+ path;// 文件的硬盘真实路径
File file = new File(realPath);
if (!file.exists()) {
file.mkdir();// 创建根目录
}
if (uploadFile.getCusPath() != null) {
realPath += uploadFile.getCusPath() + "\\";
path += uploadFile.getCusPath() + "\\";
file = new File(realPath);
if (!file.exists()) {
file.mkdir();// 创建文件自定义子目录
}
} else {
realPath += DataUtils.getDataString(DataUtils.yyyyMMdd) + "\\";
path += DataUtils.getDataString(DataUtils.yyyyMMdd) + "\\";
file = new File(realPath);
if (!file.exists()) {
file.mkdir();// 创建文件时间子目录
}
}
LogUtil.info("-------------------------step.3-------------------------------------");
String fileName = "";
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile mf = entity.getValue();// 获取上传文件对象
fileName = mf.getOriginalFilename();// 获取文件名
String extend = FileUtils.getExtend(fileName);// 获取文件扩展名
String myfilename = "";
String myhtmlfilename = "";
String noextfilename = "";// 不带扩展名
if (uploadFile.isRename()) {
noextfilename = DataUtils
.getDataString(DataUtils.yyyymmddhhmmss)
+ StringUtil.random(8);// 自定义文件名称
myfilename = noextfilename + "." + extend;// 自定义文件名称