fileUpLoaded.jsp
上传用户:u_thks
上传日期:2022-07-31
资源大小:1910k
文件大小:7k
- <%@ page language="java" contentType="text/html;charset=UTF-8"
- session="true" errorPage="err.jsp" %><%@
- include file="../GVinc/gvInclude.jsp" %><%@
- include file="../GVinc/gvUserLogin.jsp" %><jsp:useBean id="cup" scope="request" class="com.gamvan.club.user.ClubUserParameter"/>
- <jsp:useBean id="ud" scope="request" class="com.gamvan.club.manage.UpLoadDataBase"/>
- <jsp:useBean id="imo" scope="page" class="com.gamvan.image.ImageOperate" />
- <jsp:useBean id="fub" scope="page" class="com.gamvan.fileUpload.FileUpBean" />
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title><%=clubTitle%></title>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <link href="../GVimgs/favicon.ico" rel="Bookmark">
- <link rel="icon" href="../GVimgs/favicon.ico" type="image/x-icon" />
- <link rel="shortcut icon" href="../GVimgs/favicon.ico" type="image/x-icon" />
- <link href="../GVinc/main.css" rel="stylesheet" type="text/css" />
- <body>
- <%
- if(gvUserUpfileOpen==2){
- out.print("<font color="#bb0000">您的上载功能已被管理员关闭!</font>");
- out.close();
- if(true) return;
- }
- ccID = TypeChange.stringToInt(request.getParameter("ccID"));
- ccName = ParamUtils.getStringParameter(request,"ccName");
- /*
- * 整合至apache 发现如果不进行一次转码无法正确查询中文
- * 可能和apache默认编码有关,但是我在httpd.conf关闭了apache的默认编码依然不行
- * 所以只好手工作一次ISO8859-1到UTF8的编码了
- * 如果是直接用TOMCAT运行此程序则需要注销下面这句 keys=com.gamvan.tools.Gb.toUTF8(keys);
- */
- ccName=com.gamvan.tools.Gb.toUTF8(ccName);
- //格式化当前时间作为新文件名
- java.text.SimpleDateFormat isNow1 = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
- String newFileName = isNow1.format(new java.util.Date());
- Random ran = new Random();
- newFileName += String.valueOf(Math.abs(ran.nextInt()%100000));
- FileOperate fo = new FileOperate();
- String fpaths="", vpaths="";
- String fileSavePath=request.getRealPath("") + File.separator + "upFiles" + File.separator + "club" + File.separator; //绝对路径
- String fileTempPath=request.getRealPath("") + File.separator + "upFiles" + File.separator + "temp" + File.separator; //存放临时文件的路径。
- Calendar now2=Calendar.getInstance();
- int year=now2.get(Calendar.YEAR);
- int mon=now2.get(Calendar.MONTH)+1;
- String sYear = String.valueOf(year);
- String sMon = String.valueOf(mon);
- fpaths = sYear + sMon;
- fileSavePath = fo.createFolders(fileSavePath,fpaths);
- //fileSavePath += sYear + sMon + File.separator; //绝对路径
- //out.println(fileSavePath);
- vpaths = "/upFiles/club/"+ sYear + sMon +"/"; //相对路径
- //out.println(vpaths);
- //开始判断 个人上载空间是否够用
- fub.initialize(pageContext);
- fub.setMaxFileSize(clubUpfileMax*1024); //最大上传
- fub.setMyFileSize(Arith.sub(gvUserUpfile,gvUserUpfileSize)); //我的个人空间 单位Kb
- fub.setFileTempPath(fileTempPath); //存放临时文件的路径。
- fub.setFileSavePath(fileSavePath);
- fub.setAllowedType(clubUpfileExt); //允许上传的文件类型
- fub.setNewFileName(newFileName);
- boolean isOK = fub.saveFile();
-
- String fileExt="", oldFileName="", oldFilePath="";
- long fileSize = 0;
- //int fileSize = 0;
-
- if(!isOK){
- out.print(fub.getMessage());
- out.println(" <a href="javascript:history.back()">返回上一步</a>");
- out.close();
- if(true) return;
- }else{
- fileExt = fub.getFileExt();
- fileSize = fub.getFileSize();
- //fileSize = Integer.parseInt(String.valueOf(fileSizel));
- oldFileName = fub.getOldFileName();
- oldFilePath = fub.getOldFilePath();
- try{
- cup.setUserUpfileSize(TypeChange.stringToInt(String.valueOf(fileSize/1024)));
- cup.setNoEditufz(1);
- cup.setNoEditup(-1);
- cup.setActType(2); //用户参数累加
- cup.userParameter(gvUserName);
- //out.print(gvUserName);
- //水印开始
- //out.print(oldFilePath);
- if(fileExt.equals("jpg") || fileExt.equals("jpeg")){
- imo.setWaterPath(request.getRealPath("") + File.separator + "upFiles" + File.separator +"club" + File.separator);
- imo.setFilePath(fileSavePath);
- imo.setWaterImg1("gvLogo.png");
- imo.setWaterImg2("gvStr.png");
- imo.waterImage(newFileName+"."+fileExt,newFileName+"."+fileExt);
- }
- //水印结束
- String filePathAndName = vpaths + newFileName+"."+fileExt;
- out.print(writeText(newFileName+"."+fileExt, filePathAndName , fileExt));
-
- //开始写入数据库
- ud.setCfNewName(newFileName+"."+fileExt); //另存后的新文件名。
- ud.setCfOldName(oldFileName); //来源的原文件名。
- ud.setCfNewPath(vpaths); //另存后路径
- ud.setCfOldPath(oldFilePath);
- ud.setCfExt(fileExt);
- ud.setCfContentType(""); //内容型别。。
- ud.setCfSize(fileSize);
- ud.setCfType((short)1); //代表主题应用 2代表头像应用。
- ud.setCfUseID(0);
- ud.setCfUseTxt("");
- ud.setCfByUser(gvUserName);
-
- ud.setCfByIp(request.getRemoteAddr());
- ud.setCcID(ccID);
- ud.setCcName(ccName);
- ud.setCfByUserID(gvUserID);
- ud.filesAdd();
-
- ///out.println(fub.getFiledNameValue("idd"));
-
- out.println(" <strong>1</strong> 个文件被上载。");
- out.println(" <a href="upLoad.jsp?ccID="+ccID+"&ccName="+ccName+"">点击这里继续上载文件</a>。");
- out.println("<br/>文件地址:<a href=""+ clubUpfileDomain+filePathAndName.replace("/upFiles","")+ "" target="blank">"+ clubUpfileDomain+filePathAndName.replace("/upFiles","") + "</a>");
- }catch (Exception e){
- out.println("<b>Wrong selection : </b>" + e.toString());
- }
- }
- %>
- <%!
- public String writeText(String fName, String path, String ext){
- String temp = "";
- if(!clubUpfileDomain.equals("")){
- path = path.replace("/upFiles","");
- path = clubUpfileDomain+path; // + path.replace("/club/","");
- }
-
- if(ext.equals("jpg") || ext.equals("gif") || ext.equals("jpeg") || ext.equals("png")
- || ext.equals("bmp") )
- {
- temp = "<script language="javascript">parent.document.Gforms.content.value+='\n[img]"+ path +"[/img]\n'</script>";
- }
-
- else if(ext.equals("avi") || ext.equals("mpg") || ext.equals("mpeg") || ext.equals("wmv") )
- {
- temp = "<script language="javascript">parent.document.Gforms.content.value+='\n[video=500,400]"+ path +"[/video]'</script>";
- }
-
- else if(ext.equals("mp3") || ext.equals("mid") || ext.equals("wav") )
- {
- temp = "<script language="javascript">parent.document.Gforms.content.value+='\n[video=300,70]"+ path +"[/video]'</script>";
- }
-
- else if(ext.equals("swf") )
- {
- temp = "<script language="javascript">parent.document.Gforms.content.value+='\n[flash=500,400]"+ path +"[/flash]'</script>";
- }
-
- else if(ext.equals("rm") || ext.equals("rmvb"))
- {
- temp = "<script language="javascript">parent.document.Gforms.content.value+='\n[real=500,400]"+ path +"[/real]'</script>";
- }
-
- else{
- temp = "<script language="javascript">parent.document.Gforms.content.value+='\n[url]"+ path +"[/url]'</script>";
- }
- temp += "<script language="javascript">parent.document.Gforms.upfilesname.value+='"+ fName +"|'</script>";
- return temp;
- }
- %>
- </body>
- </html>