upload.jsp
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:4k
- <%@ page contentType="text/html; charset=GB2312" import="java.sql.*" import="java.lang.*" %>
- <%@ page import="com.gforce.currency.*,java.util.*,com.gforce.currency.clsupload.*" %>
- <%
- String destPathName = "/uploadfiles";
- String fileName="";
- Request m_request = new Request(request);
- String strStyleName = m_request.GetString("type");
- String strAllowFileExt = "";
- if(strStyleName.equalsIgnoreCase("FILE"))
- {
- strAllowFileExt = "rar|zip|exe|doc|xls|chm|hlp|pdf|ppt|pps";
- }
- else if(strStyleName.equalsIgnoreCase("MEDIA"))
- {
- strAllowFileExt = "rm|mp3|wav|mid|midi|ra|avi|mpg|mpeg|asf|asx|wma|mov|wmv";
- }
- else if(strStyleName.equalsIgnoreCase("FLASH"))
- {
- strAllowFileExt = "swf";
- }
- else
- {
- strAllowFileExt = "gif|jpg|jpeg|bmp|png";
- }
- if (m_request.GetString("action").equalsIgnoreCase("Remote"))
- {
- String strContent = m_request.GetString("WebEditor_UploadText");
- %>
- <HTML>
- <HEAD>
- <TITLE>远程上传</TITLE>
- <meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
- </head>
- <body>
- <textarea name="UploadText" id="UploadText" cols="75" rows="3" readonly="true" style="display:none;"><%=strContent%></textarea>
- </body>
- </html>
- <script language="javascript">
- parent.setHTML(UploadText.value);
- parent.remoteUploadOK();
- </script>
- <%
- }
- else if (m_request.GetString("action").equalsIgnoreCase("Save"))
- {
- ClsUpload upload=new ClsUpload(pageContext);
- fileName=upload.uploadFile("uploadfile", destPathName);
- fileName = fileName.substring(0,fileName.indexOf(","));
- String fileExpandName = fileName.substring(fileName.lastIndexOf(".")+1);
- if(("|" + strAllowFileExt + "|").toLowerCase().indexOf("|" + fileExpandName.toLowerCase() + "|")>-1)
- {
- out.println("<script language="javascript">parent.UploadSaved('" + fileName + "');</script>");
- }
- else
- {
- out.println("<script language="javascript">parent.UploadError("您上传的文件格式不正确,允许上传文件的扩展名为“" + strAllowFileExt + "”。上传失败!");</script>");
- upload.fileDelete(fileName);
- }
- }
- else
- {
- %>
- <HTML>
- <HEAD>
- <TITLE>文件上传</TITLE>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <style type="text/css">
- body, a, table, div, span, td, th, input, select{font:9pt;font-family: "宋体", Verdana, Arial, Helvetica, sans-serif;}
- body {padding:0px;margin:0px}
- </style>
- <script language="JavaScript" src="Dialog/dialog.js"></script>
- </head>
- <body bgcolor=menu>
- <form action="?action=save&type=<%=strStyleName%>" method=post name=myform enctype="multipart/form-data">
- <input type=file name=uploadfile size=1 style="width:100%">
- </form>
- <script language=javascript>
- var sAllowExt = "<%=strAllowFileExt%>";
- // 检测上传表单
- function CheckUploadForm() {
- if (!IsExt(document.myform.uploadfile.value,sAllowExt)){
- parent.UploadError("提示:nn请选择一个有效的文件,n支持的格式有("+sAllowExt+")!");
- return false;
- }
- return true
- }
- // 提交事件加入检测表单
- var oForm = document.myform ;
- oForm.attachEvent("onsubmit", CheckUploadForm) ;
- if (! oForm.submitUpload) oForm.submitUpload = new Array() ;
- oForm.submitUpload[oForm.submitUpload.length] = CheckUploadForm ;
- if (! oForm.originalSubmit) {
- oForm.originalSubmit = oForm.submit ;
- oForm.submit = function() {
- if (this.submitUpload) {
- for (var i = 0 ; i < this.submitUpload.length ; i++) {
- this.submitUpload[i]() ;
- }
- }
- this.originalSubmit() ;
- }
- }
- // 上传表单已装入完成
- try {
- parent.UploadLoaded();
- }
- catch(e){
- }
- </script>
- </body>
- </html>
- <%
- }
- %>