Upfile_ProductPic.asp
Upload User: ahxunteng
Upload Date: 2022-05-16
Package Size: 1606k
Code Size: 5k
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 SaveUpProductPicPath="UploadProductPic"
  7. 'const UpProductPicType="jpg|gif|png|bmp"
  8. 'const MaxProductPicSize=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 = SaveUpProductPicPath   '存放上传文件的目录
  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>(MaxProductPicSize*1024) then
  74.   msg="文件大小超过了限制,最大只能上传" & CStr(MaxProductPicSize) & "K的文件!"
  75. FoundErr=true
  76. end if
  77. fileExt=lcase(ofile.FileExt)
  78. arrUpFileType=split(UpProductPicType,"|")
  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只允许上传这几种文件类型:" & UpProductPicType
  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. msg="上传文件成功!"
  99. strJS=strJS & "parent.HtmlEdit.focus();" & vbcrlf    
  100. strJS=strJS & "var range = parent.HtmlEdit.document.selection.createRange();" & vbcrlf
  101. FileType=right(fileExt,3)
  102. select case FileType
  103.   case "jpg","gif","png","bmp"
  104. strJS=strJS & "range.pasteHTML('<img src=" & filename & ">');" & vbcrlf
  105. case "swf"
  106. strJS=strJS & "range.pasteHTML('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0>"
  107.    strJS=strJS & "<param name=movie value=" & FileName & ">"
  108.    strJS=strJS & "<param name=quality value=high>"
  109.    strJS=strJS & "<embed src=" & FileName & " quality=high pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash>"
  110. strJS=strJS & "</embed></object>');" & vbcrlf
  111. case else
  112.    strJS=strJS & "range.text='[upload=" & FileType & "]" & FileName & "[/upload]';" & vbcrlf
  113.    end select
  114. strJS=strJS & "parent.parent.myform.IncludePic.checked=true;" & vbcrlf
  115.    strJS=strJS & "parent.parent.myform.DefaultPicUrl.value='" & FileName & "';" & vbcrlf
  116. strJS=strJS & "parent.parent.myform.DefaultPicList.options[parent.parent.myform.DefaultPicList.length] = new Option('" & filename & "','" & filename & "');" & vbcrlf
  117. strJS=strJS & "parent.parent.myform.DefaultPicList.selectedIndex+=1;" & vbcrlf
  118. strJS=strJS & "if(parent.parent.myform.UploadFiles.value==''){" & vbcrlf
  119. strJS=strJS & "parent.parent.myform.UploadFiles.value+='" & filename & "';}" & vbcrlf
  120. strJS=strJS & "else{" & vbcrlf & "parent.parent.myform.UploadFiles.value+='|'+'" & filename & "';}" & vbcrlf
  121. end if
  122. strJS=strJS & "alert('" & msg & "');" & vbcrlf
  123.    strJS=strJS & "history.go(-1);" & vbcrlf
  124. strJS=strJS & "parent.HtmlEdit.focus();" & vbcrlf    
  125.    strJS=strJS & "</script>"
  126.    response.write strJS
  127. set file=nothing
  128. next
  129. set upload=nothing
  130. end sub
  131. %>