Upfile_SoftPic.asp
Upload User: ahxunteng
Upload Date: 2022-05-16
Package Size: 1606k
Code Size: 3k
Development Platform:

VBScript

  1. <%@language=vbscript codepage=936 %>
  2. <!--#include file="../Inc/config.asp"-->
  3. <!--#include file="upfile_class.asp"-->
  4. <%
  5. const upload_type=0   '上传方法:0=无惧无组件上传类,1=FSO上传 2=lyfupload,3=aspupload,4=chinaaspupload
  6. 'const SaveUpSoftPicPath="UploadSoftPic"
  7. 'const UpSoftPicType="jpg|gif|png|bmp"
  8. 'const MaxSoftPicSize=512
  9. dim upload,oFile,formName,SavePath,FileName,fileExt,oFileSize
  10. dim EnableUpload
  11. dim arrUpFileType
  12. dim ranNum
  13. dim msg,FoundErr
  14. msg=""
  15. FoundErr=false
  16. EnableUpload=false
  17. SavePath = SaveUpSoftPicPath   '存放上传文件的目录
  18. if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
  19. %>
  20. <html>
  21. <head>
  22. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  23. <style type="text/css">
  24. <!--
  25. BODY{
  26. BACKGROUND-COLOR: #E3E3E3;
  27. font-size:9pt
  28. }
  29. .tx1 { height: 20px;font-size: 9pt; border: 1px solid; border-color: #000000; color: #0000FF}
  30. -->
  31. </style>
  32. </head>
  33. <body leftmargin="2" topmargin="5" marginwidth="0" marginheight="0">
  34. <%
  35. if EnableUploadFile="No" then
  36. response.write "系统未开放文件上传功能"
  37. else
  38. if session("AdminName")="" and session("UserName")="" then
  39. response.Write("请登录后再使用本功能!")
  40. else
  41. select case upload_type
  42. case 0
  43. call upload_0()  '使用化境无组件上传类
  44. case else
  45. 'response.write "本系统未开放插件功能"
  46. 'response.end
  47. end select
  48. end if
  49. end if
  50. %>
  51. </body>
  52. </html>
  53. <%
  54. sub upload_0()    '使用化境无组件上传类
  55. set upload=new upfile_class ''建立上传对象
  56. upload.GetData(524288)   '取得上传数据,限制最大上传500K
  57. if upload.err > 0 then  '如果出错
  58. select case upload.err
  59. case 1
  60. response.write "请先选择你要上传的文件!"
  61. case 2
  62. response.write "你上传的文件总大小超出了最大限制(500K)"
  63. end select
  64. response.end
  65. end if
  66. for each formName in upload.file '列出所有上传了的文件
  67. EnableUpload=False
  68. set ofile=upload.file(formName)  '生成一个文件对象
  69. oFileSize=ofile.filesize
  70. if oFileSize<10 then
  71. msg="请先选择你要上传的文件!"
  72. FoundErr=True
  73. elseif ofilesize>(MaxSoftPicSize*1024) then
  74.   msg="文件大小超过了限制,最大只能上传" & CStr(MaxSoftPicSize) & "K的文件!"
  75. FoundErr=true
  76. end if
  77. fileExt=lcase(ofile.FileExt)
  78. arrUpFileType=split(UpSoftPicType,"|")
  79. for i=0 to ubound(arrUpFileType)
  80. if fileEXT=trim(arrUpFileType(i)) then
  81. EnableUpload=true
  82. exit for
  83. end if
  84. next
  85. if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" or fileEXT="cer" or fileEXT="cdx" then
  86. EnableUpload=false
  87. end if
  88. if EnableUpload=false then
  89. msg="这种文件类型不允许上传!nn只允许上传这几种文件类型:" & UpSoftPicType
  90. FoundErr=true
  91. end if
  92. strJS="<SCRIPT language=javascript>" & vbcrlf
  93. if FoundErr<>true then
  94. randomize
  95. ranNum=int(900*rnd)+100
  96. FileName="../"&SavePath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
  97. ofile.SaveToFile Server.mappath(FileName)   '保存文件
  98. response.write "软件图片上传成功!"
  99. response.write "文件路径是 <FONT COLOR=#FF0000>" & FileName & "</FONT> 请复制到上面的图片地址编辑框内."
  100. strJS=strJS & "parent.document.myform.SoftPicUrl.value='" & FileName & "';" & vbcrlf
  101. else
  102. strJS=strJS & "alert('" & msg & "');" & vbcrlf
  103.    strJS=strJS & "history.go(-1);" & vbcrlf
  104. end if
  105. strJS=strJS & "</script>" & vbcrlf
  106. response.write strJS
  107. set file=nothing
  108. next
  109. set upload=nothing
  110. end sub
  111. %>