⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filemanage.asp

📁 一个网络相册
💻 ASP
字号:
<% option explicit %>
<!--#include file="../function1/DBOpen.asp"-->
<%
function delit(fileType,path)
	'remove a file
	dim fso1
        set fso1=server.CreateObject("scripting.filesystemobject")    

        IF UCase(fileType) = "SINGLE" THEN
		    if fso1.FileExists(path) then 
        	fso1.DeleteFile(path)
			end if 
        END IF
        IF UCase(fileType) = "MULTI" THEN
        	fso1.DeleteFolder(path)
        END IF
end function
%>
<HTML>
<HEAD>
<TITLE>上传图片清理</TITLE>
</HEAD>
<BODY>
<form name="form1" method="post" action="filemanage.asp">
  <div align="center">
<FONT Size="+2">该操作将删除所有不在数据库中的上传图片,包括缩略图,以免产生过多的垃圾,占用服务器空间。
<input name="ok" type="hidden" id="ok" value="1">
<P>
  <input type="submit" name="Submit" value="确  定">
  </div>
</form>
<%
dim req,sortBy,priorSort,reverse,path,fso,theCurrentFolder,curFiles,currentSlot,fileItem,fname,fext,ftype,fsize,fcreate,fmod,faccess,fileCount,kind,i,j,minmax,minmaxSlot,mark,small,big,temp,delcount,ok
delcount=0
' 设定一个演示目录,:)

CONST DIRECTORY1 = "/admin/upload"
CONST DIRECTORY = "/admin/upload/smallpic" 

' 用常数定义排序方式
CONST FILE_NAME = 0          '按照名字排序……依次类推
CONST FILE_EXT = 1
CONST FILE_TYPE = 2
CONST FILE_SIZE = 3
CONST FILE_CREATED = 4
CONST FILE_MODIFIED = 5
CONST FILE_ACCESSED = 6

'获得 排序命令,默认为按照名字排序
ok=request("ok")
if ok=1 then
req = Request("sortBy")
If Len(req) < 1 Then sortBy = 0 Else sortBy = CInt(req)
req = Request("priorSort")
If Len(req) < 1 Then priorSort = -1 Else priorSort = CInt(req)

'设置倒序
If sortBy = priorSort Then
    reverse = true
    priorSort = -1
Else
    reverse = false
    priorSort = sortBy
End If
Dim theFiles( )
ReDim theFiles( 500 )
' 接下来开始我们真正的代码了。。。
path = Server.MapPath( DIRECTORY )
Set fso = CreateObject("Scripting.FileSystemObject")
Set theCurrentFolder = fso.GetFolder( path ) 
Set curFiles = theCurrentFolder.Files 
' 给这些文件做一个循环
dim rs,sql,fileType,filepath,path1,rootpath
rootPath = request.queryString("rootPath")
if rootPath = "" then rootPath = "."
path1 = server.mapPath(rootPath)
Set rs = Server.CreateObject("ADODB.Recordset")
For Each fileItem in curFiles
    fname = fileItem.Name
    fext = InStrRev( fname, "." )
    If fext < 1 Then fext = "" Else fext = Mid(fname,fext+1)
    ftype = fileItem.Type
    fsize = fileItem.Size
    fcreate = fileItem.DateCreated
    fmod = fileItem.DateLastModified
    faccess = fileItem.DateLastAccessed
    currentSlot = currentSlot + 1
    if fext="jpg" or fext="gif" or fext="bmp" then
    small="upload/smallpic/"+fname
    sql="select * from photo where small='" & trim(small) & "'"
    rs.open sql,conn,1,1
    if rs.bof and rs.eof then
    fileType="SINGLE"
    filePath=path1+ "\"+small
    fso.DeleteFile(filePath)
    theFiles(delcount) = Array(small,fext,ftype,fsize,fcreate,fmod,faccess)
    delcount=delcount+1
    end if
    rs.close
    end if
Next
'增加部分
path = Server.MapPath( DIRECTORY1 )
Set fso = CreateObject("Scripting.FileSystemObject")
Set theCurrentFolder = fso.GetFolder( path ) 
Set curFiles = theCurrentFolder.Files 
' 给这些文件做一个循环
rootPath = request.queryString("rootPath")
if rootPath = "" then rootPath = "."
path1 = server.mapPath(rootPath)
Set rs = Server.CreateObject("ADODB.Recordset")
For Each fileItem in curFiles
    fname = fileItem.Name
    fext = InStrRev( fname, "." )
    If fext < 1 Then fext = "" Else fext = Mid(fname,fext+1)
    ftype = fileItem.Type
    fsize = fileItem.Size
    fcreate = fileItem.DateCreated
    fmod = fileItem.DateLastModified
    faccess = fileItem.DateLastAccessed
    currentSlot = currentSlot + 1
    if fext="jpg" or fext="gif" or fext="bmp" then
    big="upload/"+fname
    sql="select * from photo where big='" & trim(big) & "'"
    rs.open sql,conn,1,1
    if rs.bof and rs.eof then
    fileType="SINGLE"
    filePath=path1+ "\"+big
    fso.DeleteFile(filePath)
    theFiles(delcount) = Array(big,fext,ftype,fsize,fcreate,fmod,faccess)
    delcount=delcount+1
    end if
    rs.close
    end if
Next
fileCount=delcount
'增加部分结束
%>
<CENTER>
共删除了<font color=red><%=delcount%></font>个不在数据库中的文件<P>
<%if delcount>0 then %>
<P>
<TABLE Border=1 CellPadding=3>
<TR>
    <TH><A HREF="javascript:reSort(0);">文件名</A></TH>
    <TH><A HREF="javascript:reSort(1);">扩展名</A></TH>
    <TH><A HREF="javascript:reSort(2);">类型</A></TH>
    <TH><A HREF="javascript:reSort(3);">大小</A></TH>
    <TH><A HREF="javascript:reSort(4);">建立时间</A></TH>
    <TH><A HREF="javascript:reSort(5);">上次修改时间</A></TH>
    <TH><A HREF="javascript:reSort(6);">上次存取时间</A></TH>
</TR>
<%

For i = 0 To delcount-1
    Response.Write "<TR>" & vbNewLine
    For j = 0 To UBound( theFiles(i) )
        Response.Write "    <TD>" & theFiles(i)(j) & "</TD>" & vbNewLine
    Next
    Response.Write "</TR>" & vbNewLine
Next
%>
</TABLE>
<%end if%>
<%end if%>
</BODY>
</HTML>
<!--#include file="../function/DBclose.asp"-->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -