关于文件上传组件的调试问题
发表于:2007-06-30来源:作者:点击数:
标签:
这是我的上传组件原文, vb 作的,没有任何问题!br br nbsp;nbsp;nbsp;Public Binbr Private Names()br Private Sizes()br Private Filenames()br Private Myposition()br Public Maxsizebr Public Fcountbr br Public Sub Exec()br nbsp;nbsp;nbsp;Dim Psta
这是我的上传组件原文,
vb作的,没有任何问题!<br>
<br>
Public Bin<br>
Private Names()<br>
Private Sizes()<br>
Private Filenames()<br>
Private Myposition()<br>
Public Maxsize<br>
Public Fcount<br>
<br>
Public Sub Exec()<br>
Dim Pstart, Pend, strBoundary, i, Str, Position<br>
Dim Spacestr<br>
Spacestr = "-----------------------------"<br>
Dim tempbarray, tempstr<br>
tempstr = BtoS(Bin)<br>
strBoundary = "Content-Disposition: form-data"<br>
tempbarray = Split(tempstr, strBoundary)<br>
Fcount = UBound(tempbarray)<br>
<br>
ReDim Names(Fcount)<br>
ReDim Sizes(Fcount)<br>
ReDim Filenames(Fcount)<br>
ReDim Myposition(Fcount, 2)<br>
<br>
strBoundary = StoB(strBoundary)<br>
Position = InStrB(Bin, strBoundary) + 1<br>
<br>
For i = 0 To Fcount - 1<br>
Pstart = InStrB(Position, Bin, StoB(Chr(34))) + 1<br>
Pend = InStrB(Pstart, Bin, StoB(Chr(34)))<br>
Names(i) = BtoS(MidB(Bin, Pstart, Pend - Pstart))<br>
‘’以上取表单名<br>
<br>
Pstart = Pend + 1<br>
Str = MidB(Bin, Pstart, 15)<br>
Position = InStrB(Str, StoB("filename"))<br>
If Position > 0 Then<br>
Pstart = InStrB(Pstart, Bin, StoB(Chr(34))) + 1<br>
Pend = InStrB(Pstart, Bin, StoB(Chr(34)))<br>
Str = BtoS(MidB(Bin, Pstart, Pend - Pstart))<br>
If Str = Empty Then<br>
Filenames(i) = ""<br>
Else<br>
Filenames(i) = Str<br>
Pstart = InStrB(Pend, Bin, StoB(vbCrLf & vbCrLf)) + 4<br>
Pend = InStrB(Pstart, Bin, StoB("-------")) - 2<br>
Myposition(i, 0) = Pstart<br>
Myposition(i, 1) = Pend<br>
End If<br>
Else<br>
Pstart = InStrB(Pstart, Bin, StoB(vbCrLf & vbCrLf)) + 4<br>
Pend = InStrB(Pstart, Bin, StoB("-------")) - 2<br>
Myposition(i, 0) = Pstart<br>
Myposition(i, 1) = Pend<br>
End If<br>
Position = Pend<br>
Next<br>
<br>
‘’Dim save<br>
‘’save = savetofile()<br>
‘’response.write save & "<br>"<br>
End Sub<br>
Public Function SaveFile(fieldname, mypath, newname)<br>
Dim i, tempname, temptype, p, temppath<br>
Dim binarystr() As Byte<br>
For i = 0 To Fcount - 1<br>
If fieldname = Names(i) Then<br>
tempname = Filenames(i)<br>
p = i<br>
Exit For<br>
End If<br>
Next<br>
i = p<br>
If tempname <> Empty Then<br>
If Filenames(i) <> "" Then<br>
p = InStrRev(tempname, ".")<br>
temptype = Right(tempname, Len(tempname) - p)<br>
temppath = mypath & "\" & newname & "." & temptype<br>
binarystr = MidB(Bin, Myposition(i, 0), Myposition(i, 1) - Myposition(i, 0))<br>
Open temppath For Binary As #1<br>
Put #1, , binarystr<br>
Close #1<br>
SaveFile = newname & "." & temptype<br>
Else<br>
SaveFile = "0"<br>
End If<br>
Else<br>
SaveFile = "0"<br>
End If<br>
End Function<br>
Public Function getform(fieldname)<br>
Dim i, sign, p<br>
For i = 0 To Fcount - 1<br>
If fieldname = Names(i) Then<br>
‘’getform = BtoS(MidB(values(i), 1, LenB(values(i))))<br>
sign = 1<br>
p = i<br>
Exit For<br>
End If<br>
Next<br>
If sign = 1 Then<br>
getform = BtoS(MidB(Bin, Myposition(p, 0), Myposition(p, 1) - Myposition(p, 0)))<br>
Else<br>
getform = ""<br>
End If<br>
End Function<br>
Public Function getsize(fieldname)<br>
Dim i, sign, p<br>
For i = 0 To Fcount - 1<br>
If fieldname = Names(i) Then<br>
sign = 1<br>
p = i<br>
Exit For<br>
End If<br>
Next<br>
If sign = 1 Then<br>
getsize = Myposition(p, 1) - Myposition(p, 0)<br>
Else<br>
getsize = 0<br>
End If<br>
End Function<br>
Private Function BtoS(binstr)<br>
Dim lnglen<br>
Dim tmpBin<br>
Dim strC<br>
Dim skipflag<br>
Dim i<br>
‘’中文字符Skip标志<br>
skipflag = 0<br>
strC = ""<br>
If Not IsNull(binstr) Then<br>
lnglen = LenB(binstr)<br>
For i = 1 To lnglen<br>
If skipflag = 0 Then<br>
tmpBin = MidB(binstr, i, 1)<br>
‘’判断是否中文的字符<br>
If AscB(tmpBin) > 127 Then<br>
‘’AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转<br>
strC = strC & Chr(AscW(MidB(binstr, i + 1, 1) & tmpBin))<br>
skipflag = 1<br>
Else<br>
strC = strC & Chr(AscB(tmpBin))<br>
End If<br>
Else<br>
skipflag = 0<br>
End If<br>
Next<br>
End If<br>
BtoS = strC<br>
End Function<br>
<br>
<br>
‘’把普通字符串转成二进制字符串函数<br>
Private Function StoB(varstr)<br>
Dim str2bin<br>
Dim varchar<br>
Dim varasc<br>
Dim varlow, varhigh<br>
Dim i<br>
str2bin = ""<br>
For i = 1 To Len(varstr)<br>
varchar = Mid(varstr, i, 1)<br>
varasc = Asc(varchar)<br>
‘’ asc对中文字符求出来的值可能为负数,<br>
‘’ 加上65536就可求出它的无符号数值<br>
‘’ -1在机器内是用补码表示的0xffff,<br>
‘’ 其无符号值为65535,65535=-1+65536<br>
‘’ 其他负数依次类推。<br>
If varasc < 0 Then<br>
varasc = varasc + 65535<br>
End If<br>
‘’对中文的处理:把双字节低位和高位分开<br>
If varasc > 255 Then<br>
varlow = Left(Hex(Asc(varchar)), 2)<br>
varhigh = Right(Hex(Asc(varchar)), 2)<br>
str2bin = str2bin & ChrB("&H" & varlow) & ChrB("&H" & varhigh)<br>
Else<br>
str2bin = str2bin & ChrB(AscB(varchar))<br>
End If<br>
Next<br>
StoB = str2bin<br>
End Function<br>
<br>
<br>
Private Sub Class_Terminate()<br>
Set Bin = Nothing<br>
End Sub<br>
<br>
<br>
<br>
<br>
<br>
<br>
原文转自:http://www.ltesting.net