Admin_UploadFile.asp
上传用户:lwb168
上传日期:2021-10-31
资源大小:722k
文件大小:11k
源码类别:

Email服务器

开发平台:

ASP/ASPX

  1. <!--#include file = "Include/Startup.asp"-->
  2. <!--#include file = "admin_private.asp"-->
  3. <%
  4. '☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
  5. '★                                                                  ★
  6. '☆                eWebEditor - eWebSoft在线编辑器                   ☆
  7. '★                                                                  ★
  8. '☆  版权所有: eWebSoft.com                                          ☆
  9. '★                                                                  ★
  10. '☆  程序制作: eWeb开发团队                                          ☆
  11. '★            email:webmaster@webasp.net                            ★
  12. '☆            QQ:589808                                             ☆
  13. '★                                                                  ★
  14. '☆  相关网址: [产品介绍]http://www.eWebSoft.com/Product/eWebEditor/ ☆
  15. '★            [支持论坛]http://bbs.eWebSoft.com/                    ★
  16. '☆                                                                  ☆
  17. '★  主页地址: http://www.eWebSoft.com/   eWebSoft团队及产品         ★
  18. '☆            http://www.webasp.net/     WEB技术及应用资源网站      ☆
  19. '★            http://bbs.webasp.net/     WEB技术交流论坛            ★
  20. '★                                                                  ★
  21. '☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
  22. %>
  23. <%
  24. Dim sStyleID, sUploadDir, sCurrDir, sDir
  25. sPosition = sPosition & "上传文件管理"
  26. Call Header()
  27. Call Content()
  28. Call Footer()
  29. Sub Content()
  30. If IsObjInstalled("Scripting.FileSystemObject") = False Then
  31. Response.Write "此功能要求服务器支持文件系统对象(FSO),而你当前的服务器不支持!"
  32. Exit Sub
  33. End If
  34. ' 初始化传入参数
  35. Call InitParam()
  36. Select Case sAction
  37. Case "DELALL" ' 删除所有文件
  38. Call DoDelAll()
  39. Case "DEL" ' 删除指定文件
  40. Call DoDel()
  41. Case "DELFOLDER" ' 删除文件夹
  42. Call DoDelFolder()
  43. End Select
  44. ' 显示文件列表
  45. Call ShowList()
  46. End Sub
  47. ' UploadFile目录下的所有文件列表
  48. Sub ShowList()
  49. Response.Write "<p align=right class=highlight2>" & _
  50. "<form action='?' method=post name=queryform>" & _
  51. "<b>选择样式目录:</b><select name='id' size=1 onchange=""location.href='?id='+this.options[this.selectedIndex].value"">" & InitSelect(sStyleID, "select ('样式:'+S_Name+'---目录:'+S_UploadDir),S_ID from eWebEditor_Style order by S_ID asc", "选择...") & "</select>" & _
  52. "</form></p>"
  53. If sCurrDir = "" Then Exit Sub
  54. Response.Write "<table border=0 cellpadding=0 cellspacing=0 class=list1>" & _
  55. "<form action='?id=" & sStyleID & "&dir=" & sDir & "&action=del' method=post name=myform>" & _
  56. "<tr align=center>" & _
  57. "<th width=50>类型</th>" & _
  58. "<th width=140>文件地址</th>" & _
  59. "<th width=100>大小</th>" & _
  60. "<th width=130>最后访问</th>" & _
  61. "<th width=130>上传日期</th>" & _
  62. "<th width=30>删除</th>" & _
  63. "</tr>"
  64. Dim sCurrPage, nCurrPage, nFileNum, nPageNum, nPageSize
  65. sCurrPage = Trim(Request("page"))
  66. nPageSize = 20
  67. If sCurrpage = "" Or Not IsNumeric(sCurrPage) Then
  68. nCurrPage = 1
  69. Else
  70. nCurrPage = CLng(sCurrPage)
  71. End If
  72. Dim oFSO, oUploadFolder, oUploadFiles, oUploadFile, sFileName
  73. Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
  74. On Error Resume Next
  75. Set oUploadFolder = oFSO.GetFolder(Server.MapPath(sCurrDir))
  76. If Err.Number>0 Then
  77. Response.Write "</table>无效的目录!"
  78. Exit Sub
  79. End If
  80. If sDir <> "" Then
  81. Response.Write "<tr align=center>" & _
  82. "<td><img border=0 src='sysimage/file/folderback.gif'></td>" & _
  83. "<td align=left colspan=5><a href=""?id=" & sStyleID & "&dir="
  84. If InstrRev(sDir, "/") > 1 Then
  85. Response.Write Left(sDir, InstrRev(sDir, "/") - 1)
  86. End If
  87. Response.Write """>返回上一级目录</a></td></tr>"
  88. End If
  89. Dim oSubFolder
  90. For Each oSubFolder In oUploadFolder.SubFolders
  91. Response.Write "<tr align=center>" & _
  92. "<td><img border=0 src='sysimage/file/folder.gif'></td>" & _
  93. "<td align=left colspan=4><a href=""?id=" & sStyleID & "&dir="
  94. If sDir <> "" Then
  95. Response.Write sDir & "/"
  96. End If
  97. Response.Write oSubFolder.Name & """>" & oSubFolder.Name & "</a></td>" & _
  98. "<td><a href='?id=" & sStyleID & "&dir=" & sDir & "&action=delfolder&foldername=" & oSubFolder.Name & "'>删除</a></td></tr>"
  99. Next
  100. Set oUploadFiles = oUploadFolder.Files
  101. nFileNum = oUploadFiles.Count
  102. nPageNum = Int(nFileNum / nPageSize)
  103. If nFileNum Mod nPageSize > 0 Then
  104. nPageNum = nPageNum+1
  105. End If
  106. If nCurrPage > nPageNum Then
  107. nCurrPage = 1
  108. end If
  109. Dim i
  110. i = 0
  111. For Each oUploadFile In oUploadFiles
  112. i = i + 1
  113. If i > (nCurrPage - 1) * nPageSize And i <= nCurrPage * nPageSize Then
  114. sFileName = oUploadFile.Name
  115. Response.Write "<tr align=center>" & _
  116. "<td>" & FileName2Pic(sFileName) & "</td>" & _
  117. "<td align=left><a href=""" & sCurrDir & sFileName & """ target=_blank>" & sFileName & "</a></td>" & _
  118. "<td>" & oUploadFile.size & " B </td>" & _
  119. "<td>" & oUploadFile.datelastaccessed & "</td>" & _
  120. "<td>" & oUploadFile.datecreated & "</td>" & _
  121. "<td><input type=checkbox name=delfilename value=""" & sFileName & """></td></tr>"
  122. Elseif i > nCurrPage * nPageSize Then
  123. Exit For
  124. End If
  125. Next
  126. Set oUploadFolder = Nothing
  127. Set oUploadFiles = Nothing
  128. If nFileNum <= 0 Then
  129. Response.Write "<tr><td colspan=6>指定目录下现在还没有文件!</td></tr>"
  130. End If
  131. Response.Write "</table>"
  132. If nFileNum > 0 Then
  133. ' 分页
  134. Response.Write "<table border=0 cellpadding=3 cellspacing=0 width='100%'><tr><td>"
  135. If nCurrPage > 1 Then
  136. Response.Write "<a href='?id=" & sStyleID & "&dir=" & sDir & "&page=1'>首页</a>&nbsp;&nbsp;<a href='?id=" & sStyleID & "&dir=" & sDir & "&page="& nCurrPage - 1 & "'>上一页</a>&nbsp;&nbsp;"
  137. Else
  138. Response.Write "首页&nbsp;&nbsp;上一页&nbsp;&nbsp;"
  139. End If
  140. If nCurrPage < i / nPageSize Then
  141. Response.Write "<a href='?id=" & sStyleID & "&dir=" & sDir & "&page=" & nCurrPage + 1 & "'>下一页</a>&nbsp;&nbsp;<a href='?id=" & sStyleID & "&dir=" & sDir & "&page=" & nPageNum & "'>尾页</a>"
  142. Else
  143. Response.Write "下一页&nbsp;&nbsp;尾页"
  144. End If
  145. Response.Write "&nbsp;&nbsp;&nbsp;&nbsp;共<b>" & nFileNum & "</b>个&nbsp;&nbsp;页次:<b><span class=highlight2>" & nCurrPage & "</span>/" & nPageNum & "</b>&nbsp;&nbsp;<b>" & nPageSize & "</b>个文件/页"
  146. Response.Write "</td></tr></table>"
  147. End If
  148. Response.Write "<p align=right><input type=submit name=b value=' 删除选定的文件 '> <input type=button name=b1 value=' 清空所有文件 ' onclick=""javascript:if (confirm('你确定要清空所有文件吗?')) {location.href='admin_uploadfile.asp?id=" & sStyleID & "&dir=" & sDir & "&action=delall';}""></p></form>"
  149. End Sub
  150. ' 删除指定的文件
  151. Sub DoDel()
  152. On Error Resume Next
  153. Dim sFileName, oFSO, sMapFileName
  154. Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
  155. For Each sFileName In Request.Form("delfilename")
  156. sMapFileName = Server.MapPath(sCurrDir & sFileName)
  157. If oFSO.FileExists(sMapFileName) Then
  158. oFSO.DeleteFile(sMapFileName)
  159. End If
  160. Next
  161. Set oFSO = Nothing
  162. End Sub
  163. ' 删除所有的文件
  164. Sub DoDelAll()
  165. On Error Resume Next
  166. Dim sFileName, oFSO, sMapFileName, oFolder, oFiles, oFile
  167. Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
  168. Set oFolder = oFSO.GetFolder(Server.MapPath(sCurrDir))
  169. Set oFiles = oFolder.Files
  170. For Each oFile In oFiles
  171. sFileName = oFile.Name
  172. sMapFileName = Server.MapPath(sCurrDir & sFileName)
  173. If oFSO.FileExists(sMapFileName) Then
  174. oFSO.DeleteFile(sMapFileName)
  175. End If
  176. Next
  177. Set oFile = Nothing
  178. Set oFolder = Nothing
  179. Set oFSO = Nothing
  180. End Sub
  181. ' 删除文件夹
  182. Sub DoDelFolder()
  183. On Error Resume Next
  184. Dim sFolderName, oFSO, sMapFolderName
  185. Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
  186. sFolderName = Trim(Request("foldername"))
  187. sMapFolderName = Server.Mappath(sCurrDir & sFolderName)
  188. If oFSO.FolderExists(sMapFolderName) = True Then
  189. oFSO.DeleteFolder(sMapFolderName)
  190. End If
  191. Set oFSO = Nothing
  192. End Sub
  193. ' 检测服务器是否支持某一对象
  194. Function IsObjInstalled(strClassString)
  195. On Error Resume Next
  196. IsObjInstalled = False
  197. Err = 0
  198. Dim xTestObj
  199. Set xTestObj = Server.CreateObject(strClassString)
  200. If 0 = Err Then IsObjInstalled = True
  201. Set xTestObj = Nothing
  202. Err = 0
  203. End Function
  204. ' 按文件名取图
  205. Function FileName2Pic(sFileName)
  206. Dim sExt, sPicName
  207. sExt = UCase(Mid(sFileName, InstrRev(sFileName, ".")+1))
  208. Select Case sExt
  209. Case "TXT"
  210. sPicName = "txt.gif"
  211. Case "CHM", "HLP"
  212. sPicName = "hlp.gif"
  213. Case "DOC"
  214. sPicName = "doc.gif"
  215. Case "PDF"
  216. sPicName = "pdf.gif"
  217. Case "MDB"
  218. sPicName = "mdb.gif"
  219. Case "GIF"
  220. sPicName = "gif.gif"
  221. Case "JPG"
  222. sPicName = "jpg.gif"
  223. Case "BMP"
  224. sPicName = "bmp.gif"
  225. Case "PNG"
  226. sPicName = "pic.gif"
  227. Case "ASP", "JSP", "JS", "PHP", "PHP3", "ASPX"
  228. sPicName = "code.gif"
  229. Case "HTM", "HTML", "SHTML"
  230. sPicName = "htm.gif"
  231. Case "ZIP"
  232. sPicName = "zip.gif"
  233. Case "RAR"
  234. sPicName = "rar.gif"
  235. Case "EXE"
  236. sPicName = "exe.gif"
  237. Case "AVI"
  238. sPicName = "avi.gif"
  239. Case "MPG", "MPEG", "ASF"
  240. sPicName = "mp.gif"
  241. Case "RA", "RM"
  242. sPicName = "rm.gif"
  243. Case "MP3"
  244. sPicName = "mp3.gif"
  245. Case "MID", "MIDI"
  246. sPicName = "mid.gif"
  247. Case "WAV"
  248. sPicName = "audio.gif"
  249. Case "XLS"
  250. sPicName = "xls.gif"
  251. Case "PPT", "PPS"
  252. sPicName = "ppt.gif"
  253. Case "SWF"
  254. sPicName = "swf.gif"
  255. Case Else
  256. sPicName = "unknow.gif"
  257. End Select
  258. FileName2Pic = "<img border=0 src='sysimage/file/" & sPicName & "'>"
  259. End Function
  260. ' ===============================================
  261. ' 初始化下拉框
  262. ' v_InitValue : 初始值
  263. ' s_Sql : 从数据库中取值时,select name,value from table
  264. ' s_AllName : 空值的名称,如:"全部","所有","默认"
  265. ' ===============================================
  266. Function InitSelect(v_InitValue, s_Sql, s_AllName)
  267. Dim i
  268. InitSelect = ""
  269. If s_AllName <> "" Then
  270. InitSelect = InitSelect & "<option value=''>" & s_AllName & "</option>"
  271. End If
  272. oRs.Open s_Sql, oConn, 0, 1
  273. Do While Not oRs.Eof
  274. InitSelect = InitSelect & "<option value=""" & inHTML(oRs(1)) & """"
  275. If CStr(oRs(1)) = CStr(v_InitValue) Then
  276. InitSelect = InitSelect & " selected"
  277. End If
  278. InitSelect = InitSelect & ">" & outHTML(oRs(0)) & "</option>"
  279. oRs.MoveNext
  280. Loop
  281. oRs.Close
  282. End Function
  283. ' ===============================================
  284. ' 初始化传入参数
  285. ' ===============================================
  286. Function InitParam()
  287. sStyleID = Trim(Request("id"))
  288. sUploadDir = ""
  289. If IsNumeric(sStyleID) = True Then
  290. sSql = "select S_UploadDir from eWebEditor_Style where S_ID=" & sStyleID
  291. oRs.Open sSql, oConn, 0, 1
  292. If Not oRs.Eof Then
  293. sUploadDir = oRs(0)
  294. End If
  295. oRs.Close
  296. End If
  297. If sUploadDir = "" Then
  298. sStyleID = ""
  299. Else
  300. sUploadDir = Replace(sUploadDir, "", "/")
  301. If Right(sUploadDir, 1) <> "/" Then
  302. sUploadDir = sUploadDir & "/"
  303. End If
  304. End If
  305. sCurrDir = sUploadDir
  306. ' 样式下的目录
  307. sDir = Trim(Request("dir"))
  308. If sDir <> "" Then
  309. If CheckValidDir(Server.Mappath(sUploadDir & sDir)) = True Then
  310. sCurrDir = sUploadDir & sDir & "/"
  311. Else
  312. sDir = ""
  313. End If
  314. End If
  315. End Function
  316. ' ===============================================
  317. ' 检测目录的有效性
  318. ' ===============================================
  319. Function CheckValidDir(s_Dir)
  320. Dim oFSO
  321. Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
  322. CheckValidDir = oFSO.FolderExists(s_Dir)
  323. Set oFSO = Nothing
  324. End Function
  325. %>