Tc711Com提示:ASP 直接读取文件夹内文件,可以分页浏览,可以排序,可以删除 ,亲测可用,这是处理好的代码. |
<title>文件管理器</title>
<% '711网络亲测可用,QQ:187367103
Response.Write "<table cellspacing=1 cellpadding=5 align=center bgcolor=#cccccc width='98%' class=wenjian>"
Response.Write "<tr bgcolor=#Efefef>"
Response.Write " <td>ID</td>"
Response.Write " <td>文件地址</td>"
Response.Write " <td>文件大小</td>"
Response.Write " <td>文件类型</td>"
Response.Write " <td>上传日期</td>"
Response.Write " <td>操作</td>"
Response.Write "</tr>"
tc711up="../upload/" '修改成你对应的文件夹目录.
FoldPath=Server.MapPath(""&tc711up&"")
set fso = Server.CreateObject("Scripting.FileSystemObject")
''得到目录下所有文件的信息集合
set fsoFolder=fso.GetFolder(FoldPath)
Set GetFiles =fsoFolder.files
''定义数组,和变量
Dim FileArr(),i,p,Max,OrderBy,Total,MoveAddRessStart,MoveAddRessEnd,PCount,PFSize,APFSize
Max = 20''默认的显示条数
orderBy="DESC"''排序方式,DESC倒序,ASC正序
''得到大于0的页码
P = Request.QueryString("P")
IF P <> "" Then
If IsNumeric(P) Then
IF Cint(P) > 0 Then
P = Cint(P)
Else
P = 1
End If
Else
P = 1
End IF
Else
P = 1
End IF
''定义了文件总数的数组,0为文件名,1为日期时间,2为文件大小
ReDim FileArr(Getfiles.count-1,3)
i = 0
For Each f In GetFiles
IF FilterName(Lcase(f.Name)) Then
''取出文件名
FileArr(i,0) = f.Name
''取出文件建立时间
FileArr(i,1) = f.DateCreated
FileArr(i,2) = f.Size
FileArr(i,3) = f.Type
APFSize=APFSize+f.Size
i = i + 1
End IF
Next
''得到总页数
Total=i
IF Total Mod Max = 0 Then
PCount = ToTal / Max
Else
PCount = Total \ Max + 1
End IF
IF P > PCount Then P = PCount
''对文件进行排序按日期,OrderBy等于DESC倒序,OrderBy等于ASC正序
For One = 0 To i - 1
For Two = 0 To i - 1
IF Ucase(OrderBy) = "DESC" Then
orderByConditions=(CDate(FileArr(One,1)) > CDate(FileArr(Two,1)))
ElseIF Ucase(OrderBy) = "ASC" Then
orderByConditions=(CDate(FileArr(One,1)) < CDate(FileArr(Two,1)))
End IF
IF orderByConditions Then
TempName = FileArr(Two,0)
TempTime = FileArr(Two,1)
TempSize = FileArr(Two,2)
TempType = FileArr(Two,3)
FileArr(Two,0) = FileArr(One,0)
FileArr(Two,1) = FileArr(One,1)
FileArr(Two,2) = FileArr(One,2)
FileArr(Two,3) = FileArr(One,3)
FileArr(One,0) = TempName
FileArr(One,1) = TempTime
FileArr(One,2) = TempSize
FileArr(One,3) = TempType
End IF
Next
Next
''得到当前页的文件位置,开始地址如果为第一页则其实位置是0,因为数组的下限是0
MoveAddRessStart = P * Max - Max
IF (i-1-Max) > MoveAddRessStart Then
MoveAddRessEnd=MoveAddRessStart+Max -1
Else
MoveAddRessEnd=(i-1)
End IF
''Response.write Total
''显示列表
For j = MoveAddRessStart To MoveAddRessEnd
''Response.Write FileArr(j,2)&filearr(j,0):response.end
Response.Write "<tr><td bgcolor=#ffffff>" & j+1 & "</td><td bgcolor=#ffffff><a href="&tc711up&"" & FileArr(j,0) & " target=_blank><IMG SRC="""&tc711up&""&FileArr(j,0)&""" border=0 width=100> <br>"&FileArr(j,0)&"</a></td><td bgcolor=#ffffff>" & SizeTo(FileArr(j,2)) & "</td><td bgcolor=#ffffff>" & FileArr(j,3) & "</td><td bgcolor=#ffffff>"&FileArr(j,1)&"</td><td bgcolor=#ffffff><a href='?action=del&upfilename="&FileArr(j,0)&"&p="&request("p")&"' onclick=""return confirm('确定要删除此文件吗?删除后将不能恢复!')"">删除</a></td></tr>"
PFSize = PFSize + FileArr(j,2)
Next
Response.Write "<tr><td bgcolor=#ffffff colspan=6 align=left>"
Response.Write "当前页有 <font color='#ff0000'>" & MoveAddRessEnd-MoveAddRessStart+1 & "</font> 个文件 "
Response.Write "占用空间 <font color='#ff0000'>" & SizeTo(PFSize) & " </font> "
IF P > 1 Then
Response.Write "<a href=?p=1>首页</a> <a href=?p="&p-1&">上一页</a> "
Else
Response.Write "首页 上一页 "
End IF
IF P < PCount Then
Response.Write "<a href=?p="&P+1&">下一页</a> <a href=?p="&PCount&">尾页</a> "
Else
Response.Write "下一页 尾页 "
End IF
Response.Write P&"/"&PCount&"页 "
Response.Write " 总共上传 <font color='#ff0000'>"&Total&"</font> 个文件 "
Response.Write "共 <font color='#ff0000'>" & SizeTo(APFSize) & "</font> "
Response.Write "</td></tr>"
Response.WRite "</table>"
''过滤文件扩展名
Function FilterName(FileName)
Dim Filter_Expansion_Name,ExpansionName
Filter_Expansion_Name = "|rar|jpg|bmp|gif|doc|xls|ppt|"''过滤取得文件夹中的文件类型,如果只填写htm则只取htm文件,注意文件本身不会出现在这个表中,但会计算在总数中
''得到扩展名
For Tp= Len(FileName) To 1 Step -1
IF Mid(FileName,Tp,1) = "." Then
Exit For
Else
ExpansionName = Mid(FileName,Tp,1) & ExpansionName
End IF
Next
IF Instr(1,Filter_Expansion_Name,"|" & ExpansionName & "|")>0 Then
FilterName=True
Else
FilterName=False
End If
End Function
''转换文件大小转换
Function SizeTo(PFSize)
SizeTo=0
IF PFSize>(1024*1024*1024) And (PFSize/1024/1024/1024)>0 Then
''GB转换
SizeTo=FormatNumber(PFSize/1024/1024/1024,2)&"GB"
ElseIF PFSize>(1024*1024) And (PFSize/1024/1024)>0 Then
''MB转换
SizeTo=FormatNumber(PFSize/1024/1024,2)&"MB"
ElseIF PFSize>1024 And (PFSize/1024)>0 Then
''KB转换
SizeTo=FormatNumber(PFSize/1024,2)&"KB"
ElseIF PFSize>0 Then
''byte转换
SizeTo=FormatNumber(PFsize,2)&"B"
Else
SizeTo=0&"B"
End IF
End Function
sub delfile(upfilename)
Dim fso
Dim objFSO '声明一个名称为 objFSO 的变量以存放对象实例
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(Server.MapPath(""&tc711up&""&upfilename)) Then
objFSO.DeleteFile Server.MapPath(""&tc711up&""&upfilename),True
End If
Set objFSO = Nothing '释放 FileSystemObject 对象实例内存空间
End sub
%> <%'删除图片文件代码
if request("action")="del" then
if request("upfilename")<>"" then
call delfile(request("upfilename"))
end if
response.Redirect("?p="&request("p")&"")
end if
%>
附件下载: http://bbs.tc711.com/thread-3684-1-1.html
更多的ASP 直接读取文件夹内文件,可以分页浏览,可以排序,可以删除请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2010-10-1