Commit a09b3090 by 黎配弘

尝试修复路径遍历

parent 0442250b
...@@ -17,7 +17,7 @@ import java.io.OutputStream; ...@@ -17,7 +17,7 @@ import java.io.OutputStream;
public class FileUtil { public class FileUtil {
//写到相应路径 //写到相应路径
public static boolean makefile(String path, MultipartFile file,String filename){ /*public static boolean makefile(String path, MultipartFile file,String filename){
File dir = new File(path); File dir = new File(path);
if (!dir.exists()) { if (!dir.exists()) {
...@@ -40,9 +40,9 @@ public class FileUtil { ...@@ -40,9 +40,9 @@ public class FileUtil {
} }
} }
return true; return true;
} }*/
public static boolean makefile1(String path, MultipartFile file,String filename){ /*public static boolean makefile1(String path, MultipartFile file,String filename){
File dir = new File(path); File dir = new File(path);
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
...@@ -62,5 +62,5 @@ public class FileUtil { ...@@ -62,5 +62,5 @@ public class FileUtil {
} }
} }
return true; return true;
} }*/
} }
...@@ -29,6 +29,9 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -29,6 +29,9 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -244,17 +247,37 @@ public class SchoolManagementController extends BaseController { ...@@ -244,17 +247,37 @@ public class SchoolManagementController extends BaseController {
@Permission(menuname = "上传二维码", value = "qrcodeUpload", method = RequestMethod.POST) @Permission(menuname = "上传二维码", value = "qrcodeUpload", method = RequestMethod.POST)
public ResponseData<String>xiaotuUpload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "id",required = false) String id) { public ResponseData<String>xiaotuUpload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "id",required = false) String id) {
String backgroundpath= FilePath.BACKGROUNDIMG.getValue()+"/"+DEFAULTPATH; String backgroundpath = FilePath.BACKGROUNDIMG.getValue() + "/" + DEFAULTPATH;
boolean makefile = FileUtil.makefile(backgroundpath, file,id+FILENAME); File dir = new File(backgroundpath);
Wrapper<School> wrapper = new EntityWrapper<>(); if (!dir.exists()) {
wrapper.eq("id",id); dir.mkdirs();
Map<String, Object> map = new HashMap<>(); }
map.put("service_qrcode",backgroundpath+id+FILENAME); File savePath = new File(backgroundpath, id + FILENAME);
Integer integer = schoolMapper.updateForSet(MyBatisPlusUpdateUtils.toUpdateSet(map), wrapper); OutputStream os = null;
if (integer!=1){ try {
return ResponseData.error("上传失败!"); os = new FileOutputStream(savePath);
os.write(file.getBytes());
os.flush();
Wrapper<School> wrapper = new EntityWrapper<>();
wrapper.eq("id",id);
Map<String, Object> map = new HashMap<>();
map.put("service_qrcode",backgroundpath+id+FILENAME);
Integer integer = schoolMapper.updateForSet(MyBatisPlusUpdateUtils.toUpdateSet(map), wrapper);
if (integer!=1){
return ResponseData.error("上传失败!");
}
return ResponseData.success("上传成功" );
} catch (Exception e) {
log.error("上传文件失败:" + e.getMessage(), e);
return ResponseData.error("上传失败" + e.getMessage());
} finally {
if (os != null) {
try{
os.close();
}catch(Exception e) {}
}
} }
return ResponseData.success("上传成功" );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment