|
@@ -220,6 +220,7 @@ public class BannerTemplateController extends SimpleController {
|
|
|
|
|
|
public @ResponseBody String upload(Model model,HttpServletResponse response,HttpServletRequest request,Long advertiserId) throws IOException{
|
|
|
String uploadName;
|
|
|
+ String resetName;
|
|
|
String fileType;
|
|
|
//文件路径
|
|
|
String path;
|
|
@@ -251,10 +252,11 @@ public class BannerTemplateController extends SimpleController {
|
|
|
if(file != null){
|
|
|
//取得当前上传文件的文件名称(不加路径)
|
|
|
uploadName = file.getOriginalFilename();
|
|
|
-
|
|
|
+ resetName = resetName(uploadName);
|
|
|
//获取文件类型
|
|
|
fileType = uploadName.substring(uploadName.lastIndexOf(".") + 1);
|
|
|
|
|
|
+
|
|
|
//判断文件类型
|
|
|
if(!noStuffixSet.contains(fileType)){
|
|
|
return "不支持此文件类型";
|
|
@@ -268,7 +270,8 @@ public class BannerTemplateController extends SimpleController {
|
|
|
|
|
|
|
|
|
//处理上传文件路径
|
|
|
- path = getLocalFilePath(uploadName);
|
|
|
+ path = getLocalFilePath(resetName);
|
|
|
+ System.out.println(path);
|
|
|
System.out.println("qqqqqqq+==="+path);
|
|
|
|
|
|
File localFile = new File(path);
|
|
@@ -295,13 +298,13 @@ public class BannerTemplateController extends SimpleController {
|
|
|
//取上传文件父级目录
|
|
|
String absolutePath = localFile.getParentFile().getAbsolutePath();
|
|
|
//生成缩略图路径名
|
|
|
- pathSmall = absolutePath.concat(File.separator).concat("small_").concat(uploadName);
|
|
|
+ pathSmall = absolutePath.concat(File.separator).concat("small_").concat(resetName);
|
|
|
//生成缩略图
|
|
|
compressPicture(localFile,pathSmall,150,60);
|
|
|
//判断是否需要缩放
|
|
|
if((width*_height)==(_width*height)){
|
|
|
//压缩文件上传路径
|
|
|
- String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(uploadName);
|
|
|
+ String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(resetName);
|
|
|
//生成压缩图
|
|
|
compressPicture(localFile,compressPath, _width,_height);
|
|
|
//设置文件上传路径
|
|
@@ -340,6 +343,7 @@ public class BannerTemplateController extends SimpleController {
|
|
|
|
|
|
public @ResponseBody String replace(Model model,HttpServletResponse response,HttpServletRequest request,Long bannerTemplateId) throws IOException{
|
|
|
String uploadName;
|
|
|
+ String resetName;
|
|
|
String fileType;
|
|
|
//文件路径
|
|
|
String path;
|
|
@@ -366,6 +370,7 @@ public class BannerTemplateController extends SimpleController {
|
|
|
if(file != null){
|
|
|
//取得当前上传文件的文件名称(不加路径)
|
|
|
uploadName = file.getOriginalFilename();
|
|
|
+ resetName = resetName(uploadName);
|
|
|
|
|
|
//获取文件类型
|
|
|
fileType = uploadName.substring(uploadName.lastIndexOf(".") + 1);
|
|
@@ -379,7 +384,7 @@ public class BannerTemplateController extends SimpleController {
|
|
|
if(uploadName.trim() !=""){
|
|
|
|
|
|
//处理上传文件路径
|
|
|
- path = getLocalFilePath(uploadName);
|
|
|
+ path = getLocalFilePath(resetName);
|
|
|
|
|
|
File localFile = new File(path);
|
|
|
//上传目录不存在,则新建目录
|
|
@@ -397,13 +402,13 @@ public class BannerTemplateController extends SimpleController {
|
|
|
//取上传文件父级目录
|
|
|
String absolutePath = localFile.getParentFile().getAbsolutePath();
|
|
|
//生成缩略图路径名
|
|
|
- pathSmall = absolutePath.concat(File.separator).concat("small_").concat(uploadName);
|
|
|
+ pathSmall = absolutePath.concat(File.separator).concat("small_").concat(resetName);
|
|
|
//生成缩略图
|
|
|
compressPicture(localFile,pathSmall,150,60);
|
|
|
|
|
|
if((width*_height)==(_width*height)){
|
|
|
//压缩文件上传路径
|
|
|
- String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(uploadName);
|
|
|
+ String compressPath =absolutePath.concat(File.separator).concat("compress_").concat(resetName);
|
|
|
//生成压缩图
|
|
|
compressPicture(localFile,compressPath, _width,_height);
|
|
|
//设置文件上传路径
|
|
@@ -436,7 +441,16 @@ public class BannerTemplateController extends SimpleController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+//处理图片名称
|
|
|
+ public String resetName(String uploadName){
|
|
|
+ String fileType = fileType = uploadName.substring(uploadName.lastIndexOf("."));
|
|
|
+ uploadName = new StringBuilder()
|
|
|
+ .append(System.currentTimeMillis())
|
|
|
+ .append(fileType)
|
|
|
+ .toString();
|
|
|
+ return uploadName;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//处理上传文件的绝对路径
|
|
|
public String getLocalFilePath(String fileName){
|