<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim upfile_Stream
Class upload_F
dim Form,File,Version
Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="化境编程界HTTP上传程序 Version 1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_Stream=CreateObject("Adodb.Stream")
upfile_Stream.mode=3
upfile_Stream.type=1
upfile_Stream.open
upfile_Stream.write Request.BinaryRead(Request.TotalBytes)
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
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
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
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
End Class
</SCRIPT>
这段代码好象限制了上传图片的大小了,我想把他的限制取消或者降低限制,该如何修改啊???
拜托各位了,小弟刚来,没有多少分,把我所有的都给你们吧!
6 个解决方案
#1
怎么没人帮我解决啊?自己顶一下,不违规吧?
#2
这个已经修改好了,不过建议你不要不限制大小,因为如果上传的文件太大程序会出错的
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim Data_SoFia
Class upload_SoFia
dim objForm,objFile,intFilesize
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
intFilesize=102400*2
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 Then
Response.Write ("请选择文件")
Exit Sub
Response.End()
End If
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
End If
set tStream = Server.CreateObject("adodb.stream")
set Data_SoFia = Server.CreateObject("adodb.stream")
Data_SoFia.Type = 1
Data_SoFia.Mode =3
Data_SoFia.Open
On Error Resume Next
Data_SoFia.Write Request.BinaryRead(Request.TotalBytes)
If Err<>0 Then
err.Clear
Response.Write "<div align=center><br>您上传的文件不合法,大小超出范围。</div>"
Response.End
End If
Data_SoFia.Position=0
RequestData =Data_SoFia.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_SoFia.Position = iFormStart
Data_SoFia.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_SoFia.Position = iInfoEnd
Data_SoFia.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
if Request.TotalBytes>1 and Request.TotalBytes<intFilesize Then Data_SoFia.Close
set Data_SoFia =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_SoFia.position=FileStart
Data_SoFia.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim Data_SoFia
Class upload_SoFia
dim objForm,objFile,intFilesize
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
intFilesize=102400*2
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 Then
Response.Write ("请选择文件")
Exit Sub
Response.End()
End If
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
End If
set tStream = Server.CreateObject("adodb.stream")
set Data_SoFia = Server.CreateObject("adodb.stream")
Data_SoFia.Type = 1
Data_SoFia.Mode =3
Data_SoFia.Open
On Error Resume Next
Data_SoFia.Write Request.BinaryRead(Request.TotalBytes)
If Err<>0 Then
err.Clear
Response.Write "<div align=center><br>您上传的文件不合法,大小超出范围。</div>"
Response.End
End If
Data_SoFia.Position=0
RequestData =Data_SoFia.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_SoFia.Position = iFormStart
Data_SoFia.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_SoFia.Position = iInfoEnd
Data_SoFia.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
if Request.TotalBytes>1 and Request.TotalBytes<intFilesize Then Data_SoFia.Close
set Data_SoFia =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_SoFia.position=FileStart
Data_SoFia.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
</SCRIPT>
#3
哦,修正一下
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
' End If
这个end if 也要加上单引号
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
' End If
这个end if 也要加上单引号
#4
intFilesize=102400*2
这是限制大小的变量,102400*2就是200k
这是限制大小的变量,102400*2就是200k
#5
师兄,很感谢你的答案,但是我用你的代码替换后,出现了新的问题:
另一个文件的“set upload=new upload_f ''建立上传对象”出了问题,上传大图片时,提示:“Microsoft VBScript 运行时错误 错误 '800a01fa'
类没有被定义: 'upload_f'
/admin/product/add1.asp,行 8 ”
其中,“行8”就是“set upload=new upload_f”
能不能劳烦你帮我彻底帮我解决这个问题,如果可以,告诉我你的联系方法吧。
我的QQ:631908023,急等啊~~~~~~~~~~~~~~~
另一个文件的“set upload=new upload_f ''建立上传对象”出了问题,上传大图片时,提示:“Microsoft VBScript 运行时错误 错误 '800a01fa'
类没有被定义: 'upload_f'
/admin/product/add1.asp,行 8 ”
其中,“行8”就是“set upload=new upload_f”
能不能劳烦你帮我彻底帮我解决这个问题,如果可以,告诉我你的联系方法吧。
我的QQ:631908023,急等啊~~~~~~~~~~~~~~~
#6
set upload=new upload_SoFia
这是建立对象的方法
这是建立对象的方法
#1
怎么没人帮我解决啊?自己顶一下,不违规吧?
#2
这个已经修改好了,不过建议你不要不限制大小,因为如果上传的文件太大程序会出错的
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim Data_SoFia
Class upload_SoFia
dim objForm,objFile,intFilesize
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
intFilesize=102400*2
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 Then
Response.Write ("请选择文件")
Exit Sub
Response.End()
End If
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
End If
set tStream = Server.CreateObject("adodb.stream")
set Data_SoFia = Server.CreateObject("adodb.stream")
Data_SoFia.Type = 1
Data_SoFia.Mode =3
Data_SoFia.Open
On Error Resume Next
Data_SoFia.Write Request.BinaryRead(Request.TotalBytes)
If Err<>0 Then
err.Clear
Response.Write "<div align=center><br>您上传的文件不合法,大小超出范围。</div>"
Response.End
End If
Data_SoFia.Position=0
RequestData =Data_SoFia.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_SoFia.Position = iFormStart
Data_SoFia.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_SoFia.Position = iInfoEnd
Data_SoFia.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
if Request.TotalBytes>1 and Request.TotalBytes<intFilesize Then Data_SoFia.Close
set Data_SoFia =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_SoFia.position=FileStart
Data_SoFia.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
</SCRIPT>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
dim Data_SoFia
Class upload_SoFia
dim objForm,objFile,intFilesize
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
intFilesize=102400*2
set objForm=Server.CreateObject("Scripting.Dictionary")
set objFile=Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes<1 Then
Response.Write ("请选择文件")
Exit Sub
Response.End()
End If
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
End If
set tStream = Server.CreateObject("adodb.stream")
set Data_SoFia = Server.CreateObject("adodb.stream")
Data_SoFia.Type = 1
Data_SoFia.Mode =3
Data_SoFia.Open
On Error Resume Next
Data_SoFia.Write Request.BinaryRead(Request.TotalBytes)
If Err<>0 Then
err.Clear
Response.Write "<div align=center><br>您上传的文件不合法,大小超出范围。</div>"
Response.End
End If
Data_SoFia.Position=0
RequestData =Data_SoFia.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_SoFia.Position = iFormStart
Data_SoFia.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_SoFia.Position = iInfoEnd
Data_SoFia.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
if Request.TotalBytes>1 and Request.TotalBytes<intFilesize Then Data_SoFia.Close
set Data_SoFia =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_SoFia.position=FileStart
Data_SoFia.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=false
end function
End Class
</SCRIPT>
#3
哦,修正一下
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
' End If
这个end if 也要加上单引号
'如果要限制大小请把下边五行代码的单引号去掉
' If Request.TotalBytes>intFilesize Then
' Response.Write ("<div align=center><br>请确认您上传的图片文件不大于"&intFilesize/1024&"K</div>")
' Response.End()
' Exit Sub
' End If
这个end if 也要加上单引号
#4
intFilesize=102400*2
这是限制大小的变量,102400*2就是200k
这是限制大小的变量,102400*2就是200k
#5
师兄,很感谢你的答案,但是我用你的代码替换后,出现了新的问题:
另一个文件的“set upload=new upload_f ''建立上传对象”出了问题,上传大图片时,提示:“Microsoft VBScript 运行时错误 错误 '800a01fa'
类没有被定义: 'upload_f'
/admin/product/add1.asp,行 8 ”
其中,“行8”就是“set upload=new upload_f”
能不能劳烦你帮我彻底帮我解决这个问题,如果可以,告诉我你的联系方法吧。
我的QQ:631908023,急等啊~~~~~~~~~~~~~~~
另一个文件的“set upload=new upload_f ''建立上传对象”出了问题,上传大图片时,提示:“Microsoft VBScript 运行时错误 错误 '800a01fa'
类没有被定义: 'upload_f'
/admin/product/add1.asp,行 8 ”
其中,“行8”就是“set upload=new upload_f”
能不能劳烦你帮我彻底帮我解决这个问题,如果可以,告诉我你的联系方法吧。
我的QQ:631908023,急等啊~~~~~~~~~~~~~~~
#6
set upload=new upload_SoFia
这是建立对象的方法
这是建立对象的方法