up.jsp
4.19 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
114
115
116
117
118
119
120
121
122
123
124
125
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<jsp:useBean id="mySmartUpload" scope="page"class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="p" class="weaver.album.PhotoComInfo" scope="page" />
<%@ page import='java.io.File'%>
<%@ page import='java.util.ArrayList'%>
<%@ page import="weaver.general.GCONST" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.general.TimeUtil" %>
<%@ page import='weaver.hrm.User'%>
<%@ page import='weaver.hrm.HrmUserVarify'%>
<%@ page import='weaver.album.PhotoSequence'%>
<%@ page import='weaver.image.Thumbnail'%>
<jsp:useBean id="DateTransformer" class="weaver.dateformat.DateTransformer" scope="page" />
<%
User user = HrmUserVarify.getUser (request , response) ;
if(user == null) return ;
int intParentId = Util.getIntValue(request.getParameter("parentId"));
if(intParentId==-1){
intParentId=1;
}
String parentId = String.valueOf(intParentId);
int userId = user.getUID();
int pId = 0;
String uploadImgIDs = "";
int uploadImgSizeSum = 0;
String picturePath = "";
rs.executeSql("SELECT picturePath FROM systemset");
if(rs.next()){
picturePath = Util.null2String(rs.getString("picturePath"));
}
String physicalPath =GCONST.getRootPath()+ "album" + File.separatorChar + "UploadFolder";
String physicalPathThumbnail = physicalPath;//缩略图存放在/Album/UploadFolder/thumbnail下
if(!("".equals(picturePath))){//如果设置了路径,图片存放在指定目录下
physicalPath = picturePath;
}
File saveDir = new File(physicalPath);
if(!(saveDir.exists())){
saveDir.mkdir();
}
//计算文件上传个数
int count = 0;
mySmartUpload.initialize(pageContext);
//依据form的内容上传
mySmartUpload.upload("UTF-8");
ArrayList imgArray = new ArrayList();
//将上传的文件一个一个取出来处理
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
//取出一个文件
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
//如果文件存在,则做存档操作
if (!myFile.isMissing()) {
String fileName = myFile.getFileName();
pId = PhotoSequence.getInstance().get();
if(fileName.lastIndexOf("\\")!=-1){
fileName = fileName.substring(fileName.lastIndexOf("\\")+1, fileName.length());
}
if(Util.isExcuteFile(fileName)) continue;
String newFileName = String.valueOf(pId);
//文件存放位置
myFile.saveAs(physicalPath + File.separator + newFileName,mySmartUpload.SAVE_PHYSICAL);
String filesize = Util.round(String.valueOf(myFile.getSize()/1000), 1);
if(filesize.equals("0")) filesize="1";
//缩略图
String[] param = {physicalPath+File.separator+newFileName, physicalPathThumbnail+File.separator+"thumbnail"+File.separator+newFileName, "96", "200", "100"};
Thumbnail.create(param);
String[] paramImg = {""+pId, fileName, filesize, newFileName, DateTransformer.getServerDateTime(TimeUtil.getCurrentTimeString())};
imgArray.add(paramImg);
count++;
}
}
String ancestorId = p.getAncestorId(parentId);
String sql = "";
int size = imgArray.size();
for(int i=0;i<size;i++){
String[] _imgArray = (String[])imgArray.get(i);
String tempchar = File.separator;
if("mysql".equals(rs.getDBType())&&"\\".equals(File.separator)){
tempchar = "\\\\";
physicalPath = physicalPath.replaceAll("\\\\","\\\\\\\\");
}
sql = "INSERT INTO AlbumPhotos (id, parentId, isFolder, subFolderCount, photoName, photoSize, photoPath, photoDescription, thumbnailPath, userid, postdate, "+
"subcompanyId,orderNum) VALUES ("+_imgArray[0]+", "+parentId+", '0', 0, '"+_imgArray[1]+"', "+_imgArray[2]+", '"+physicalPath+tempchar+_imgArray[3]+
"', '', '"+tempchar+"album"+tempchar+"UploadFolder"+tempchar+"thumbnail"+tempchar+_imgArray[3]+"', "+userId+
", '"+_imgArray[4]+"', "+ancestorId+",-1)";
rs.executeSql(sql);
p.addPhotoInfoCache(_imgArray[0]);
}
//sqlserver使用触发器
if(rs.getDBType().equals("oracle")||rs.getDBType().equals("mysql")){
p.updateCountAndSize(ancestorId, parentId);
}
p.updatePhotoInfoCache(parentId);
%>
<html>
<body>
</body>
</html>