📄 upimg_submit.jsp
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=GBK"%>
<%@ page import="com.doone.util.*"%>
<%@ page import="com.doone.data.*"%>
<%@ page import="com.doone.fj1w.bbs.*"%>
<%@ page import="com.doone.uurm.*"%>
<%@ page import="com.doone.fj1w.fjmgr.config.UpImageBean"%>
<%@ page import="com.doone.fj1w.fjmgr.sysmgr.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%// 以下是必须的内容
UpImageBean contentBean = new UpImageBean();
String sAttchment = request.getParameter("ATTCHMENT");
String sPurviewId = request.getParameter("PURVIEWID");
String sContentId = request.getParameter("CONTENTID");//用于已有的记录修改原有的
long lboardId= Long.parseLong(sPurviewId);//栏目ID
String sAttchs[] = null;
// 权限检查。同时读取栏目编号。
WebAuth auth = WebAuth.getInstance(request);
if (sAttchment != null) {
sAttchs = sAttchment.split("::");
}
// contentBean.delContent(lboardId);
DacClient db = new DacClient();
try { TF_Content content=null;
db.beginTransaction(-1);
if ((sContentId==null)||(sContentId.trim().length()==0)){
content = new TF_Content(db);}
else{
content = new TF_Content(db,Long.parseLong(sContentId));
}
// 处理附件内容。
List attchList = new ArrayList();
boolean hasAttch = false;
int isfail=0;
for (int i = 0; sAttchs != null && i < sAttchs.length; i++) {
if (sAttchs[i] == null)
continue;
String aAttch[] = ExtString.split(sAttchs[i], "||", null);
if (aAttch.length != 2)
continue;
String sOldFileName = aAttch[1];
String sFileName = aAttch[0];
String sPathName = "/view/bbs/UploadFile/";
String sFullName = sPathName + sFileName;
String realName = application.getRealPath(sFullName);
File file = new File(realName);
String sFullType=sFileName.substring(sFileName.lastIndexOf(".")).toUpperCase();
if ((( sFullType.indexOf("JPG"))==-1)&&(( sFullType.indexOf("GIF"))==-1)&&(( sFullType.indexOf("SWF"))==-1)){
out.write("<script language=javascript>alert('限制上传除JPG,GIF,SWF格式外的文件');history.go(-1);history.go(-1);</script>");
isfail=1;
break;
}
if (file.length()>2400000){
out.write("<script language=javascript>alert('限制上传大于2M的文件');history.go(-1);history.go(-1);</script>");
isfail=1;
break;
}
if (file.exists() && file.isFile()) {
TF_Attchment attchment = new TF_Attchment(db);
attchment.setFile_Name(sOldFileName);
attchment.setFile_Size(file.length());
String sExtName = sFileName.substring(sFileName.lastIndexOf("."));
attchment.setAttch_Type("5");
attchment.setFile_Type(ContentType.getContentType(sExtName));
attchment.setUpLoad_Time(new Date());
attchment.setContent_ID(content.getContent_ID());
byte[] bs1 = new byte[(int) attchment.getFile_Size() + 1];
FileInputStream is = new FileInputStream(file);
if (is.read(bs1, 0, (int) attchment.getFile_Size()) != -1) {
attchment.setFile_Content(bs1);
}
else {
FileLogger.getLogger().warn("文件读取数据失败。");
continue;
}
is.close(); // 关闭连接。
attchList.add(attchment);
if (!file.delete()) { // 删除文件系统中的附件。
FileLogger.getLogger().warn("附件删除失败:" + sFileName);
}
}
else {
FileLogger.getLogger().info("文件不存在:" + sFileName + ",可能内容中的图片无法显示。");
continue;
}
}
if (isfail==0){
// 插件新内容。
if (hasAttch) {
content.setExist_Attch("1");
}
else {
content.setExist_Attch("0");
}
if (content.getFirst_Content_ID() == 0) {
content.setFirst_Content_ID(content.getContent_ID());
}
content.setBoard_ID(lboardId);
content.setAccount_ID(auth.getUserID());
content.setAccount_Name(auth.getUserCode());
content.setUser_Name(auth.getUserName());
content.setCreate_Time(new Date());
content.setTip_Order(0);
content.setExtract_Sign("0");
content.setReply_Count(0);
content.setReply_Account_ID(auth.getUserID());
content.setReply_User_Name(auth.getUserName());
content.setLast_Click_Time(new Date());
content.setLast_Reply_Time(new Date());
content.setContentType("04");//模块扩展图标
content.save();
// 保存嵌入内容中的附件。
StringBuffer attchName = new StringBuffer();
for (int i = 0; i < attchList.size(); i++) {
TF_Attchment attch = (TF_Attchment) attchList.get(i);
if (attchName.indexOf("||" + attch.getFile_Name() + "||") != -1) {
throw new RuntimeException("您上传的附件有重名,请检查后重新上传。");
}
attchName.append("||").append(attch.getFile_Name()).append("||");
attch.save();
}
// 处理独立的附件。
db.endTransaction(true);
out.write("<script language=javascript>alert('保存成功!');window.close();</script>");
}}
catch (Exception ex) {
try {
db.endTransaction(false);
}
catch (Exception e) {}
out.write("<script language=javascript>window.location.href='" + request.getContextPath()
+ "/view/sysmgr/OperFailure.jsp?error=" + Util.Replace(ex.getMessage())
+ "';</script>");
FileLogger.getLogger().warn(ex.getMessage(), ex);
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -