📄 muma.asp
字号:
<%
if session("flag")="" then
response.redirect "adminlogin.asp"
response.end
end if
%>
<%if session("flag")>1 then
response.write"<SCRIPT language=JavaScript>alert('对不起,你没有这个权限!');"
response.write"javascript:history.go(-1)</SCRIPT>"
response.end
end if%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<title>上传文件管理</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<%
Set fso = Server.CreateObject("Scripting.FileSystemObject")
path=Trim(Request.QueryString("path"))
if path="" then path="../upload/"
action=Trim(Request.QueryString("action"))
select case action
case ""
Set objFolder = fso.GetFolder(server.MapPath(path))
%>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="top"><br><font color="#FF0000"><strong>后 台 文 件 上 传</strong></font></td>
</tr></table><br>
<table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#000000">
<tr align="center" bgcolor="#CCCCCC">
<td width="40%" height="22">文件名(右键下载)</td>
<td width="20%" height="22">文件类型</td>
<td width="20%" height="22">文件大小</td>
<td width="20%" height="22">文件删除</td>
</tr>
<%
For Each objItem In objFolder.Files
%>
<tr bgcolor="#ffffff">
<td width="40%" height="22"> <a href="../upload/<%= objItem.Name %>" target=_blank><%= objItem.Name %></a></td>
<td width="20%" align="center" height="22"><%= objItem.Type %></td>
<td width="20%" height="22" align="center"><%= formatnumber(objItem.Size,0) %> 字节</td>
<td width="20%" height="22" align="center"><a href="muma.asp?action=delfile&path=<%= path&objItem.name %>">删除</a></td>
</tr>
<%
Next
Set objItem = Nothing
Set objFolder = Nothing
%>
</table>
<center>
<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></center>
<%
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)
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
'----------------------------------------------------------------------
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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -