📄 admin_uploadclass.asp
字号:
<%OPTION EXPLICIT%>
<%Server.ScriptTimeout=5000%>
<!--#include file="Include/Config.asp"-->
<!--#include file="Include/SQLAdmin.asp"-->
<!--#include file="Include/Conn.asp"-->
<!--#include file="Include/IPLockAdmin.asp"-->
<%dim Admin_Purview:Admin_Purview="1"%>
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<meta http-equiv="Content-Language" Content="zh-CN">
<meta name="Keywords" Content="">
<meta name="Description" Content="">
<link type="text/css" rel="stylesheet" href="Include/Style.css">
</head>
<body leftmargin="0" topmargin="2" bgcolor="#FFFFFF">
<!--#include file="Include/Session.asp"-->
<Script RunAt="Server" Language="VBScript">
dim Data_5xsoft
Class upload_5xsoft
dim objForm,objFile,Version
Public function Form(strForm)
strForm=lcase(strForm)
if not objForm.exists(strForm) then
Form=""
else
Form=objForm(strForm)
end if
end function
Public function File(strFile)
strFile=lcase(strFile)
if not objFile.exists(strFile) then
set File=new FileInfo
else
set File=objFile(strFile)
end if
end function
Private Sub Class_Initialize
dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
Version="5xsoft.com V2.0"
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set Data_5xsoft = Server.CreateObject("adodb.stream")
Data_5xsoft.Type = 1
Data_5xsoft.Mode =3
Data_5xsoft.Open
Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes)
Data_5xsoft.Position=0
RequestData =Data_5xsoft.Read
iFormStart = 1
iFormEnd = LenB(RequestData)
vbCrlf = chrB(13) & chrB(10)
sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
iStart = LenB (sStart)
iFormStart=iFormStart+iStart+1
while (iFormStart + 10) < iFormEnd
iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
tStream.Type = 1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iFormStart
Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
tStream.Close
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestData,sStart)
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set theFile=new FileInfo
'取得文件名
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
'取得文件类型
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart =iInfoEnd
theFile.FileSize = iFormStart -iInfoEnd -3
theFile.FormName=sFormName
if not objFile.Exists(sFormName) then
objFile.add sFormName,theFile
end if
else
'如果是表单项目
tStream.Type =1
tStream.Mode =3
tStream.Open
Data_5xsoft.Position = iInfoEnd
Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sFormValue = tStream.ReadText
tStream.Close
if objForm.Exists(sFormName) then
objForm(sFormName)=objForm(sFormName)&", "&sFormValue
else
objForm.Add sFormName,sFormValue
end if
end if
iFormStart=iFormStart+iStart+1
wend
RequestData=""
set tStream =Nothing
End Sub
Private Sub Class_Terminate
if Request.TotalBytes>0 then
objForm.RemoveAll
objFile.RemoveAll
set objForm=Nothing
set objFile=Nothing
Data_5xsoft.Close
set Data_5xsoft =Nothing
end if
End Sub
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
End Class
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileType,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
End Sub
Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=true
if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
Data_5xsoft.position=FileStart
Data_5xsoft.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=Nothing
SaveAs=false
end function
End Class
</Script>
<%
dim upload,file,formName,iCount,FolderNameNew
dim GuFolderPath
set upload=new upload_5xsoft '建立上传对象
' Response.write upload.Version&"<br><br>" '显示上传类的版本
if upload.form("GuFolderPath")<>"" then
GuFolderPath=upload.form("GuFolderPath")
call FolderNameCheck(GuFolderPath)
GuFolderPath=upload.form("GuFolderPath")
if right(GuFolderPath,1)<>"/" then GuFolderPath=GuFolderPath&"/"
elseif upload.form("GuFolderPath")="" and UploadPictureFolder0<>"" then
GuFolderPath=UploadPictureFolder0
call FolderNameCheck(GuFolderPath)
GuFolderPath=UploadPictureFolder0
if right(GuFolderPath,1)<>"/" then GuFolderPath=GuFolderPath&"/"
else
GuFolderPath=""
end if
iCount=0
for each formName in upload.objForm '列出所有form数据
' Response.write formName&"="&upload.form(formName)&"<br>"
next
' Response.write "<br><br>"
for each formName in upload.objFile '列出所有上传了的文件
set file=upload.file(formName)
if file.FileSize>0 then
dim FileExtF,FileExtY,FileExtOK,ii,jj
FileExtF=split(File.FileName,".")
for jj=0 to ubound(FileExtF)
next
FileExtY=0
FileExtOK=split(UploadFileExtDefault,"|")
for ii=0 to ubound(FileExtOK)
if FileExtOK(ii)=FileExtF(jj-1) then
FileExtY=1
exit for
end if
next
if FileExtY=0 then
GuSystemMessage "上传失败,不允许上传的文件类型"
elseif file.FileSize>UploadFileSizeDefault*1024 then
GuSystemMessage "上传失败,单个文件大小超过限制,最大"&UploadFileSizeDefault&"*1024 字节,1K=1024字节"
else
dim FileNameOK
if UploadFileAutoName="1" then
FileNameOK=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&iCount&"."&FileExtF(jj-1)
else
FileNameOK=file.FileName
end if
file.SaveAs Server.MapPath(GuFolderPath&FileNameOK) '保存文件
' Response.write file.FilePath&file.FileName&"(大小:"&file.FileSize&" 字节) => "&GuFolderPath&FileNameOK&" 成功! <br>"
GuSystemMessage GuFolderPath&FileNameOK
iCount=iCount+1
end if
else
GuSystemMessage "上传失败,请选择要上传的文件"
end if
set file=Nothing
next
set upload=Nothing
' GuSystemMessage iCount&" 个文件上传成功!"
Sub FolderNameCheck(FolderNameNew)
dim Letters,i,c
Letters="+=:;,[]<>\|*?"
for i=1 to len(FolderNameNew)
c=mid(FolderNameNew,i,1)
if inStr(Letters,c)<>0 then
GuSystemMessage "上传失败,文件夹名称含有特殊字符"
end if
next
GuFolderPath=server.MapPath(GuFolderPath)
Set GuFSO=Server.CreateObject("Scripting.FileSystemObject")
if GuFSO.FolderExists(GuFolderPath)=false then
GuFSO.CreateFolder(GuFolderPath)
end if
Set GuFSO=Nothing
End sub
Sub GuSystemMessage(GuMessageText)
dim GuFilepathOKIW
if Request.QueryString("T")="E" or Request.QueryString("T")="P" then
GuFilepathOKIW="164"
else
GuFilepathOKIW="380"
end if
Response.write "<form name=""Admin_UploadClass"">" &vbCrLf
Response.write " <input type=""text"" size=""1"" value="""&GuMessageText&""" name=""GuFilepathOK"" class=""Admin_InputText"" style=""width:"&GuFilepathOKIW&";background-color:#FFFFFF;""> <input type=""button"" onClick=""JavaScript:history.go(-1);"" value=""返回"" name=""Back"" class=""Admin_InputText"" style=""width:40;background-color:#EBE9ED;""> <input type=""button"" name=""Copy"" value=""复制"" onclick=""JavaScript:Admin_UploadClass.GuFilepathOK.select();document.execCommand('Copy');"" class=""Admin_InputText"" style=""width:40;background-color:#EBE9ED;"">" &vbCrLf
Response.write "</form>"
' Response.end
End sub
%>
<!--#include file="Include/Message.asp"-->
</body>
</html>
<%CloseDatabase%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -