SocialUploadOperate.jsp
3.12 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
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="weaver.file.FileUpload" %>
<%@ page import="weaver.general.*" %>
<%@ page import="weaver.hrm.*" %>
<%@ page import="java.util.*" %>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="weaver.conn.RecordSet"%>
<%
response.setHeader("cache-control", "no-cache");
response.setHeader("pragma", "no-cache");
response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
//request.setCharacterEncoding("utf-8");
BaseBean logr = new BaseBean();
User user = HrmUserVarify.getUser (request , response) ;
if(user == null) return ;
request.setAttribute("emessage_savepath", "emessage");
FileUpload fu = new FileUpload(request,"utf-8");
String uploadType=Util.null2String(fu.getParameter("uploadType"));
JSONObject result=new JSONObject();
String docid="";
try {
docid = fu.uploadFiles("Filedata");
if (Util.getIntValue(docid) <= 0) {
logr.writeLog("-------------emessage---发送文件-------------upload---error--docid is null--");
result.put("errorcode", "-1");
result.put("errormsg", "Corrupt form data: premature ending!");
out.println(result);
return;
} else {
RecordSet rs=new RecordSet();
Calendar today = Calendar.getInstance();
String formatdate = Util.add0(today.get(Calendar.YEAR), 4) + "-"
+ Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-"
+ Util.add0(today.get(Calendar.DAY_OF_MONTH), 2);
String formattime = Util.add0(today.get(Calendar.HOUR_OF_DAY), 2) + ":"
+ Util.add0(today.get(Calendar.MINUTE), 2) + ":" + Util.add0(today.get(Calendar.SECOND), 2);
rs.executeSql("insert into fileclean (imagefileid,comefrom,filecreatedate,filecreatetime) values ("+docid+",'emessage','"+formatdate+"','"+formattime+"')");
}
} catch (Exception e) {}
if("image".equals(uploadType)||"pasteimage".equals(uploadType)){
String url=""+docid+"";
String filename = System.currentTimeMillis() + ".png";
String filesize = "";
RecordSet recordSet=new RecordSet();
if("pasteimage".equals(uploadType)){
recordSet.execute("update ImageFile set imagefilename='"+filename+"' where imagefileid="+docid);
}
recordSet.execute("select fileSize from ImageFile where imagefileid =" + docid);
recordSet.next();
filesize = recordSet.getString(1);
// InputStream is=ImageFileManager.getInputStreamById(Util.getIntValue(docid));
// String base64Str = null;
// try{
// SocialImgCompress imgCompress=new SocialImgCompress(is);
// base64Str=imgCompress.compressImg(240, 240).replaceAll("\r\n","").replaceAll("\r","").replaceAll("\n","");
// }catch(Exception e){
// new BaseBean().writeLog(e.toString());
// }
// result.put("content",base64Str);
result.put("imgUrl",url);
result.put("filename", Util.forHtml(filename));
result.put("filesize", filesize);
out.println(result);
}else{
RecordSet recordSet=new RecordSet();
recordSet.execute("select imagefilename, fileSize from ImageFile where imagefileid =" + docid);
recordSet.next();
result.put("fileId", docid);
result.put("filename", Util.forHtml(recordSet.getString(1)));
result.put("filesize", recordSet.getString(2));
out.println(result);
}
%>