UpFileSave.asp
资源名称:1.rar [点击查看]
上传用户:yrf020
上传日期:2007-07-24
资源大小:1287k
文件大小:5k
源码类别:

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

开发平台:

HTML/CSS

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