📄 personfileupload.jsp
字号:
<%@page language="java" contentType="text/html;charset=GBK"%>
<%@page import="java.util.*,java.text.*,java.io.*,oa.main.DealString,com.jspsmart.upload.*,java.io.File,oa.bean.*,java.sql.*"%>
<%
//数据处理过程
oa.bean.PersonFileBean myFileBean = null;
oa.bean.MailBean mlBean = null;
DocBean doc = null;
oa.bean.RightBean rb = null;
try{
myFileBean = new oa.bean.PersonFileBean();
mlBean = new oa.bean.MailBean();
DealString ds = new DealString();
doc=new DocBean();
rb = new oa.bean.RightBean();
if ( mlBean.getConn() == null
|| doc.getConn() == null
|| rb.getConn() == null)
{
%>
数据库无法响应,请<a href="javascript:window.history.back(-1);">返回</a>重试
<%out.close();
}
String strPersonNo = ds.toString((String)session.getAttribute("zgbh"));
String strCMD = ds.toString((String)request.getParameter("txt_cmd"));
String strParentID = ds.toString((String)request.getParameter("txt_parentID"));
if (strParentID.equals("")) strParentID="0";
String strFileID = ds.toString((String)request.getParameter("txt_fileID"));
if (strFileID.equals("")) strFileID="0";
String args="txt_parentID="+strParentID+"&txt_fileID="+strFileID;
rb.setUID(strPersonNo);
String strTotalSpace = rb.getConfValue("文件柜大小");
int nUsed = myFileBean.getUsedSpace(strPersonNo);
int nTotal = Integer.parseInt(strTotalSpace);
int nTotalByte = nTotal*1024*1024;
int nMaxFileSize = nTotalByte - nUsed;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>文件上传</title>
<link href="../css/person.css" type=text/css rel=stylesheet>
</head>
<Script>
function UpLoad_Perform(){
document.all.formFile.action = "personFileUpload.jsp?<%=args%>&txt_cmd=UPLOAD_PERFORM";
document.all.formFile.submit();
}
function backToParent(){
opener.form1.txt_cmd.value = "";
opener.form1.action = "personFile.jsp";
opener.form1.submit();
window.close();
}
</Script>
<BODY bgColor=menu topmargin=15 leftmargin=15 ><CENTER>
<%
//执行上传文件选择动作------------------------------------------------------------------------------>
if (strCMD.equals("UPLOAD")) {
%>
<form name="formFile" method="post" action="/personFileUpload.jsp" enctype="multipart/form-data" >
<FIELDSET align=left>
<LEGEND align=left>文件上传</LEGEND>
文件:<input type="file" name="filename" size=20>
<input type="button" value="上传" onclick="UpLoad_Perform()">
</fieldset></form>
<%
}
if (strCMD.equals("UPLOAD_PERFORM")){
SmartUpload su = null;
%>
<input type="button" value=" 返 回 " name="B3" onclick="backToParent()">
<%
try{
su = new SmartUpload();
su.initialize(config,request,response);
su.setTotalMaxFileSize(10240000);
su.upload();
String NewFileName="";
String RealFileName = "";
for (int i=0;i<su.getFiles().getCount();i++){
com.jspsmart.upload.File file = su.getFiles().getFile(i);
if (file.isMissing()) continue;
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>文件名</TD><TD>" + file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件长度</TD><TD>" + file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件扩展名</TD><TD>" + file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名</TD><TD>"+ file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR>");
myFileBean.setPersonID(strPersonNo);
myFileBean.setParentID(strParentID);
String strFileName = ds.toString(file.getFileName());
RealFileName = strFileName;
String strFileExt = ds.toString(file.getFileExt());
String strFileSize = ds.toString(Integer.toString(file.getSize()));
String strFileStorePath = myFileBean.getFileStorePath();
String strFileStoreName = myFileBean.getNewStoreFileName(file.getFileName());
NewFileName = strFileStoreName;
String upmonth = ds.getDateTime();
String saveDirectory = strFileStorePath;
java.io.File f = new java.io.File(saveDirectory+upmonth.substring(0,4));
if(!f.exists())
{
f.mkdir();
}
f = new java.io.File(saveDirectory+upmonth.substring(0,4)+"\\"+upmonth.substring(5,7));
if(!f.exists())
{
f.mkdir();
}
f = new java.io.File(saveDirectory+upmonth.substring(0,4)+"\\"+upmonth.substring(5,7)+"\\"+upmonth.substring(8,10));
if(!f.exists())
{
f.mkdir();
}
strFileStoreName=new String(upmonth.substring(0,4)+"\\"+upmonth.substring(5,7)+"\\"+upmonth.substring(8,10)+"\\"+strFileStoreName);
String strFileFullPath = strFileStorePath + strFileStoreName;
file.saveAs(strFileFullPath ,su.SAVE_PHYSICAL);
myFileBean.addFile(strFileName,strFileExt,strFileSize,strFileStoreName);
}//end for i
if (myFileBean.getUsedSpace(strPersonNo)>nTotalByte){
java.io.File file=new java.io.File("d:\\uploads\\personfiles\\"+NewFileName);
if (file.exists()){
file.delete();
}
String str="delete from zz_grwjb where zgbh='"+strPersonNo+"' and wjlj like '%"+NewFileName+"%'";
doc.ExecuteSQL(str);
%>
<script language=javascript>
alert("您上传的文件大小超过了规定值!");
</script>
<%
}
else{
%>
<script language=javascript>
backToParent();
</script>
<%
}
}catch(Exception e){
oa.main.Logger.log("ERROR:cominfo.add.article.upfile.jsp=>");
e.printStackTrace(oa.main.Logger.log);
out.print("文件太大,无法上传"+e);
}
finally{
su.stop();
su=null;
System.gc();
}
}
%>
</body>
</html>
<%}catch(Exception e){oa.main.Logger.log("ERROR:oa.person.personFileUpload.jsp=>");e.printStackTrace(oa.main.Logger.log);}
finally{
if(rb!=null) rb.closeConn();
if(myFileBean!=null)myFileBean.closeConn();
if(mlBean!=null) mlBean.closeConn();
if(doc!=null) doc.closeConn();
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -