=======================upload_class.asp================
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim upfile_Stream
Class upload_file
dim Form,File,Version,Count,sCount
Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="蓝蝶精品网www.ChinaOK.net[改自盗香老农]"
Count=0
sCount=0
dim theUpPath,theMapPath
theMapPath=server.MapPath("..") '注意路径问题。
if right(theMapPath,1)<>"\" then theMapPath=theMapPath&"\"
theUpPath=theMapPath&Request.QueryString("filepath")
'Response.Write theUpPath
if Request.TotalBytes<1 then Exit Sub
'set Form=server.CreateObject("Scripting.Dictionary")
'set File=server.CreateObject("Scripting.Dictionary")
set upfile_Stream=CreateObject("Adodb.Stream")
vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
'File.add mFormName,theFile
'/+++++++++++++++++++++++++++
if mFileSize>0 then
theFile.SaveAs theUpPath&theFile.FileName 'mformPath&file.FileName
Count=Count+1
sCount=sCount+1
theFile.PrintInfo theFile,theUpPath&theFile.FileName
else
Count=Count+1
theFile.PrintInfo theFile,theUpPath&theFile.FileName
end if
'++++++++++++++++/
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
'form.Add mFormName,mFormValue
' Response.Write "$"&cstr(mFormName)&"|"&cstr(mFormValue)
end if
iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub
'注释
Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_Stream.EOS then Exit for
c=ascB(upfile_Stream.Read(1))
If c > 127 Then
if upfile_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function
'注释
Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr) '将文字变为十六进制的串
theLen=LenB(Str)
for i=theStart to upfile_Stream.Size-theLen
if i>upfile_Stream.size then exit Function
upfile_Stream.Position=i-1
if AscB(upfile_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function
'释放类
Private Sub Class_Terminate
' form.RemoveAll
' file.RemoveAll
'set form=nothing
' set file=nothing
upfile_Stream.close
set upfile_Stream=nothing
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
'将字符串变为二进制的串
Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class
'初始化, 保存文件
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub
'保存文件,从 upfile_Stream里截取文件
Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_Stream.position=FileStart-1
upfile_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
End function
'输出文件信息
Public sub PrintInfo(theFile,fullpath)
dim str_print
str_print= "<li>本地路径:"&theFile.FilePath&theFile.FileName&" <font color=#ff00cc>大小</font>:"&theFile.FileSize&" Byte<br> 上传路径: "&FullPath
if theFile.FileSize>0 then
str_print=str_print & " <font color=red>成功!</font>"
else str_print=str_print & " <font color=red>失败!</font>"
end if
Response.Write str_print
End sub
End Class
好了。
现在我就可以继续帖了。这里不让连续帖3个以上的。
========================upload.asp================
<%OPTION EXPLICIT%>
<%
if Session("master")="" then response.redirect "login.asp"
dim rndInt
rndInt=cstr(Request.QueryString("fid"))
if strcomp(rndInt,session("formid"))<>0 then HtmEnd "请不要重复递交!",1,"upfile.asp"
session("formid")="0"
Server.ScriptTimeOut=5000
sub HtmEnd(info,isback,dir)
if info<>"" then Response.Write("<script language=""javascript"">alert('"&info&"');</script>")
select case isback
case 1
Response.Write("<script language=""javascript"">history.back();</script>")
case 2
Response.Write("<script language=""javascript"">location.href='"&dir&"';</script>")
end select
Response.write("</body></html>")
Response.End
end sub
%>
<!--#include file="upload_class.asp"-->
<html>
<head>
<title>蓝蝶精品网... Web Document Explorer.....上传结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="admin.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" text="#000000" oncontextmenu=self.event.returnValue=false >
<table border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#CCCCCC" width="91" height="23">
<tr><td align="left" valign="middle" height="18" width="18"> </td>
<td bgcolor="#CCCCCC" align="left" valign="middle" height="18" width="67">文件上传</td>
</tr></table><br><br>
<table width="542" border="1" cellspacing="0" cellpadding="5" align="center" bordercolordark="#CCCCCC" bordercolorlight="#000000">
<tr bgcolor="#CCCCCC">
<td height="22" align="left" valign="middle" bgcolor="#CCCCCC" width="540">蓝 蝶 精 品 网... Web Document Explorer ...上传结果</td>
</tr>
<tr align="left" valign="middle" bgcolor="#eeeeee">
<td bgcolor="#eeeeee" height="92" width="540">
<%iCount=0
dim upload,file,formName,formPath,iCount,act,sCount
set upload=new upload_file
iCount=upload.Count
sCount=upload.sCount
set upload=nothing ''删除此对象