upload.jsp
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:4k
源码类别:

OA系统

开发平台:

Java

  1. <%@ page contentType="text/html; charset=GB2312" import="java.sql.*" import="java.lang.*" %>
  2. <%@ page import="com.gforce.currency.*,java.util.*,com.gforce.currency.clsupload.*" %>
  3. <%
  4. String destPathName = "/uploadfiles";
  5. String fileName="";
  6. Request m_request = new Request(request);
  7. String strStyleName = m_request.GetString("type");
  8. String strAllowFileExt = "";
  9. if(strStyleName.equalsIgnoreCase("FILE"))
  10. {
  11.   strAllowFileExt = "rar|zip|exe|doc|xls|chm|hlp|pdf|ppt|pps";
  12. }
  13. else if(strStyleName.equalsIgnoreCase("MEDIA"))
  14. {
  15.   strAllowFileExt = "rm|mp3|wav|mid|midi|ra|avi|mpg|mpeg|asf|asx|wma|mov|wmv";
  16. }
  17. else if(strStyleName.equalsIgnoreCase("FLASH"))
  18. {
  19.   strAllowFileExt = "swf";
  20. }
  21. else
  22. {
  23.   strAllowFileExt = "gif|jpg|jpeg|bmp|png";
  24. }
  25. if (m_request.GetString("action").equalsIgnoreCase("Remote"))
  26. {
  27.   String strContent = m_request.GetString("WebEditor_UploadText");
  28.   %>
  29. <HTML>
  30. <HEAD>
  31. <TITLE>远程上传</TITLE>
  32. <meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
  33. </head>
  34. <body>
  35. <textarea name="UploadText" id="UploadText" cols="75" rows="3" readonly="true" style="display:none;"><%=strContent%></textarea>
  36. </body>
  37. </html>
  38. <script language="javascript">
  39. parent.setHTML(UploadText.value);
  40. parent.remoteUploadOK();
  41. </script>
  42.   <%
  43. }
  44. else if (m_request.GetString("action").equalsIgnoreCase("Save"))
  45. {
  46.   ClsUpload upload=new ClsUpload(pageContext);
  47.   fileName=upload.uploadFile("uploadfile", destPathName);
  48.   fileName = fileName.substring(0,fileName.indexOf(","));
  49.   String fileExpandName = fileName.substring(fileName.lastIndexOf(".")+1);
  50.   if(("|" + strAllowFileExt + "|").toLowerCase().indexOf("|" + fileExpandName.toLowerCase() + "|")>-1)
  51.   {
  52.       out.println("<script language="javascript">parent.UploadSaved('" + fileName + "');</script>");
  53.   }
  54.   else
  55.   {
  56.       out.println("<script language="javascript">parent.UploadError("您上传的文件格式不正确,允许上传文件的扩展名为“" + strAllowFileExt + "”。上传失败!");</script>");
  57.       upload.fileDelete(fileName);
  58.   }
  59. }
  60. else
  61. {
  62. %>
  63. <HTML>
  64. <HEAD>
  65. <TITLE>文件上传</TITLE>
  66. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  67. <style type="text/css">
  68. body, a, table, div, span, td, th, input, select{font:9pt;font-family: "宋体", Verdana, Arial, Helvetica, sans-serif;}
  69. body {padding:0px;margin:0px}
  70. </style>
  71. <script language="JavaScript" src="Dialog/dialog.js"></script>
  72. </head>
  73. <body bgcolor=menu>
  74. <form action="?action=save&type=<%=strStyleName%>" method=post name=myform enctype="multipart/form-data">
  75. <input type=file name=uploadfile size=1 style="width:100%">
  76. </form>
  77. <script language=javascript>
  78. var sAllowExt = "<%=strAllowFileExt%>";
  79. // 检测上传表单
  80. function CheckUploadForm() {
  81.   if (!IsExt(document.myform.uploadfile.value,sAllowExt)){
  82.     parent.UploadError("提示:nn请选择一个有效的文件,n支持的格式有("+sAllowExt+")!");
  83.     return false;
  84.   }
  85.   return true
  86. }
  87. // 提交事件加入检测表单
  88. var oForm = document.myform ;
  89. oForm.attachEvent("onsubmit", CheckUploadForm) ;
  90. if (! oForm.submitUpload) oForm.submitUpload = new Array() ;
  91. oForm.submitUpload[oForm.submitUpload.length] = CheckUploadForm ;
  92. if (! oForm.originalSubmit) {
  93.   oForm.originalSubmit = oForm.submit ;
  94.   oForm.submit = function() {
  95.     if (this.submitUpload) {
  96.       for (var i = 0 ; i < this.submitUpload.length ; i++) {
  97.         this.submitUpload[i]() ;
  98.       }
  99.     }
  100.     this.originalSubmit() ;
  101.   }
  102. }
  103. // 上传表单已装入完成
  104. try {
  105.   parent.UploadLoaded();
  106. }
  107. catch(e){
  108. }
  109. </script>
  110. </body>
  111. </html>
  112. <%
  113. }
  114. %>