UpFileSave.asp
上传用户:dbstep
上传日期:2022-08-06
资源大小:2803k
文件大小:5k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

ASP/ASPX

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <% Server.scriptTimeout=300 %>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>保存文件</title>
  7. <link rel="stylesheet" href="Images/CssAdmin.css">
  8. <script language="JavaScript"> 
  9. <!-- 
  10. function CopyPath(FilePath,FileSize)
  11. {
  12.     var str=location.toString()
  13.     var Result=((((str.split('?'))[1]).split('='))[1]);
  14. window.opener.editForm(Result).focus();
  15. window.opener.document.editForm(Result).value=FilePath;
  16.     if (Result == "FileUrl")
  17. {
  18.    window.opener.document.editForm.FileSize.value=FileSize;
  19.     }
  20. window.opener=null;
  21.     window.close();
  22. }
  23. //--> 
  24. </script> 
  25. </head>
  26. <!--#include file="UpFileClass.asp"-->
  27. <body >
  28. <table width=100% border=0 align="center" cellpadding="12" cellspacing="1" bgcolor="#CCCCCC">
  29.   <tr>
  30.     <td width=100% height=100% align="center" bgcolor="#EBF2F9" class=tablebody1 >
  31. <%
  32. dim Upload,File,FormName,SaveToPath,FileName,FileExt
  33. dim RanNum
  34. call UpFile()
  35. '===========无组件上传(upload_0)====================
  36. sub UpFile()
  37.   set Upload=new UpFile_Class '建立上传对象
  38.   Upload.GetData (1024*1024*15) '取得上传数据,此处即为15M
  39.   if Upload.err > 0 then
  40.     select case Upload.err
  41.       case 1
  42.         Response.Write "请先选择您要上传的文件,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
  43.       case 2
  44.         Response.Write "文件大小超过了限制15M,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
  45.     end select
  46.     exit sub
  47.   else
  48.     SaveToPath=Upload.form("SaveToPath") '文件保存目录,此目录必须为程序可读写
  49.     if SaveToPath="" then
  50.       SaveToPath="../"
  51.     end if
  52.     '在目录后加(/)
  53.     if right(SaveToPath,1)<>"/" then 
  54.       SaveToPath=SaveToPath&"/"
  55.     end if 
  56.     for each FormName in Upload.file '列出所有上传了的文件
  57.       set file=Upload.file(FormName) '生成一个文件对象
  58.       if file.Filesize<100 then
  59.         response.write "请先选择您要上传的文件,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
  60.         response.end
  61.       end if
  62.       FileExt=lcase(File.FileExt)
  63.       if CheckFileExt(FileEXT)=false then
  64.         response.write "文件格式不允许上传,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
  65.         response.end
  66.       end if
  67.       randomize timer
  68.       RanNum=int(9000*rnd)+1000
  69.       Filename=SaveToPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&Second(now)&RanNum&"."&fileExt
  70.       if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
  71.         Result=file.SaveToFile(Server.mappath(FileName)) '保存文件
  72.         if Result="ok" then
  73.   response.write "<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
  74.           response.write "<tr>"
  75.           response.write "<td width='60' height='30'>上传成功:</td>"
  76.           response.write "<td nowrap><font color='#ff0000'>"&File.FilePath&file.FileName&"</font></td>"
  77.           response.write "</tr>"
  78.           response.write "<tr>"
  79.           response.write "<td nowrap height='30'>保存路径:</td>"
  80.           response.write "<td nowrap><input type='text' size='56' class='textfield' value='"&right(FileName,len(FileName))&"'></td>"
  81.           response.write "</tr>"
  82.           response.write "<tr>"
  83.           response.write "<td nowrap height='30'>文件大小:</td>"
  84.           response.write "<td nowrap><input type='text' size='56' class='textfield' value='"&GainFileSize(file.Filesize)&"'></td>"
  85.           response.write "</tr>"   
  86.           response.write "<tr>"
  87.           response.write "<td height='36' colspan='2' valign='bottom' align='center'><input name='CopyPath' type='button' class='button' value='拷贝文件路径'  onclick=""CopyPath('"&right(FileName,len(FileName))&"','"&GainFileSize(file.Filesize)&"')""></td>"
  88.           response.write "</tr>"
  89.           response.write "</table>"
  90.         else
  91.           response.write File.FilePath&file.FileName&"上传失败&nbsp;!"&Result&"<br>"
  92.         end if
  93.       end if
  94.       set file=nothing
  95.     next
  96.     set Upload=nothing
  97.   end if
  98. end sub
  99. '判断文件类型是否合格
  100. Private Function CheckFileExt (FileEXT)
  101.   dim ForumUpload
  102.   ForumUpload="exe,gif,jpg,jpeg,rar,zip,doc"
  103.   ForumUpload=split(ForumUpload,",")
  104.   for i=0 to ubound(ForumUpload)
  105.     if lcase(FileEXT)=lcase(trim(ForumUpload(i))) then
  106.       CheckFileExt=true
  107.       exit Function
  108.     else
  109.       CheckFileExt=false
  110.     end if
  111.   next
  112. End Function
  113. Private Function GainFileSize (SizeByte)
  114.   if SizeByte < 1024*1024 then
  115.     GainFileSize=round(SizeByte/1024,2) & "&nbsp;KB"
  116.   else  
  117.     GainFileSize=round(SizeByte/1024/1024,2) & "&nbsp;MB"
  118.   end if
  119. End Function
  120. %>
  121.     </td>
  122.   </tr>
  123. </table>
  124. </body>
  125. </html>