FileUploadUtils.java
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.jflyfox.system.file.util;
import java.io.File;
import com.jfinal.kit.PathKit;
import com.jflyfox.modules.admin.site.TbSite;
import com.jflyfox.util.PathUtils;
import com.jflyfox.util.StrUtils;
public class FileUploadUtils {
public static final int UPLOAD_MAX = 10 * 1024 * 1024;
/**
* 基础目录
*/
private static final String BASE_PATH = PathKit.getWebRootPath() + File.separator;
/**
* 基础JFLYFOX目录
*/
private static final String JFLYFOX_PATH = "jflyfox" + File.separator;
/**
* 上传临时目录
*/
private static final String UPLOAD_TMP_PATH = "tmp";
/**
* 临时路径
*
* 2016年4月27日 下午4:07:23 flyfox 369191470@qq.com
*
* @param site
* @param type
* @return
*/
public static String getUploadTmpPath(TbSite site) {
String sitePath = getSitePath(site);
String path = JFLYFOX_PATH + sitePath + UPLOAD_TMP_PATH;
return path;
}
/**
* 上传路径
*
* 2016年4月27日 下午4:07:28 flyfox 369191470@qq.com
*
* @param site
* @param type
* @return
*/
public static String getUploadPath(TbSite site, String type) {
String sitePath = getSitePath(site);
String path = JFLYFOX_PATH + sitePath + type;
File file = new File(BASE_PATH + path);
if (!file.exists()) {
file.mkdirs();
}
return path;
}
/**
* 获取站点路径
*
* 2017年4月5日 下午2:23:42 flyfox 369191470@qq.com
*
* @param site
* @return
*/
public static String getSitePath(TbSite site) {
String sitePath = site == null || StrUtils.isEmpty(site.getTemplate()) ? ""
: (site.getTemplate() + File.separator);
return rebuild(sitePath);
}
/**
* 获取根路径
*
* 2017年4月5日 下午1:57:33 flyfox 369191470@qq.com
*
* @return
*/
public static String getBasePath() {
return rebuild(File.separator + JFLYFOX_PATH);
}
/**
* 获取路径根路径
*
* 2017年4月5日 下午1:54:45 flyfox 369191470@qq.com
*
* @return
*/
public static String getRootPath() {
return rebuild(PathKit.getWebRootPath());
}
/**
* 重构路径
*
* 2017年4月5日 下午1:55:59 flyfox 369191470@qq.com
*
* @param path
* @return
*/
public static String rebuild(String path) {
return PathUtils.rebuildNoDecode(path);
}
}