<%
'--日志--
'w "内容",值
Function w(nameValue,valueValue)
response.Write "" & nameValue & ":" & valueValue &"<br>" 
End FunctionDim FormData, FormSize, Divider, bCrLf
FormSize = Request.TotalBytes
FormData = Request.BinaryRead(FormSize)bCrLf = ChrB(13) & ChrB(10)
Divider = LeftB(FormData, InStrB(FormData, bCrLf) - 1) '--日志--
response.Write FormData
'--日志--
w "=====","====="
'--日志--
w "FormSize",FormSize
'--日志--
w "Divider",Divider
'将上传的文件保存到path所指定的目录下面。
'Formfield   上传表单的"file"域名
'Path   要保存文件的服务器绝对路径,形式为:"d:\path\subpath"或"d:\path\subpath\"
'MaxSize   限制上传文件的最大长度,以KByte为单位
'SavType   服务器保存文件的方式:
'   0   唯一文件名方式,如果有同名则自动改名;
'   1   报错方式,如果有同名则出错;
'   2   覆盖方式,如果有同名则覆盖原来的文件
Function SaveFile(FormFileField, Path, MaxSize, SavType)
    Dim StreamObj, StreamObj1
    Set StreamObj = Server.CreateObject("ADODB.Stream")
    Set StreamObj1 = Server.CreateObject("ADODB.Stream")
    StreamObj.Mode = 3
    StreamObj1.Mode = 3
    StreamObj.Type = 1
    StreamObj1.Type = 1
    SaveFile =""
    StartPos = LenB(Divider) + 2
'--日志--
w "StartPos",StartPos    FormFileField = Chr(34) & FormFileField & Chr(34) '--日志--
w "FormFileField",FormFileField    If Right(Path, 1) <>"\" Then
        Path = Path & "\"
    End If '--日志--
w "FormFileField",StartPos > 0
    Do While StartPos > 0
        strlen = InStrB(StartPos, FormData, bCrLf) - StartPos
        SearchStr = MidB(FormData, StartPos, strlen) '--日志--
w "strlen",strlen
'--日志--
w "SearchStr",SearchStr
        If InStr(bin2str(SearchStr), FormFileField) > 0 Then
'--日志--
w "Path",Path            FileName = bin2str(GetFileName(SearchStr, Path, SavType)) '--日志--
w "FileName",FileName           If FileName <>"" Then
'--日志--
w "Divider",Divider
'--日志--
w "InStrB",instrb(StartPos, FormData, Divider)                FileStart = InStrB(StartPos, FormData, bCrLf & bCrLf) + 4
                FileLen = InStrB(StartPos, FormData, Divider) - 2 - FileStart
'--日志--
w "FileStart",FileStart
'--日志--
w "FileLen",FileLen
'--日志--
w "MaxSize",MaxSize                If FileLen <= MaxSize * 1024 Then
                    FileContent = MidB(FormData, FileStart, FileLen)
                    StreamObj.Open
                    StreamObj1.Open                    StreamObj.Write FormData
                    StreamObj.Position = FileStart -1
                    StreamObj.CopyTo StreamObj1, FileLen
                    If SavType = 0 Then
                        SavType = 1
                    End If
                    StreamObj1.SaveToFile Path & FileName, SavType
                    StreamObj.Close
                    StreamObj1.Close
                    If SaveFile <>"" Then
                        SaveFile = SaveFile &"," & FileName
                    Else
                        SaveFile = FileName
                    End If
                Else
                    If SaveFile <>"" Then
                        SaveFile = SaveFile &",*TooBig*"
                    Else
                        SaveFile ="*TooBig*"
                    End If
                End If
            End If
        End If
        If InStrB(StartPos, FormData, Divider) < 1 Then
            Exit Do
        End If
        StartPos = InStrB(StartPos, FormData, Divider) + LenB(Divider) + 2
    Loop
End FunctionFunction GetFormVal(FormName)
    GetFormVal =""
    StartPos = LenB(Divider) + 2
    FormName = Chr(34) & FormName & Chr(34)
    Do While StartPos > 0
        strlen = InStrB(StartPos, FormData, bCrLf) - StartPos
        SearchStr = MidB(FormData, StartPos, strlen)
        If InStr(bin2str(SearchStr), FormName) > 0 Then
            ValStart = InStrB(StartPos, FormData, bCrLf & bCrLf) + 4
            ValLen = InStrB(StartPos, FormData, Divider) - 2 - ValStart
            ValContent = MidB(FormData, ValStart, ValLen)
            If GetFormVal <>"" Then
                GetFormVal = GetFormVal &"," & bin2str(ValContent)
            Else
                GetFormVal = bin2str(ValContent)
            End If
        End If
        If InStrB(StartPos, FormData, Divider) < 1 Then
            Exit Do
        End If
        StartPos = InStrB(StartPos, FormData, Divider) + LenB(Divider) + 2
    Loop
End FunctionFunction bin2str(binstr)
    Dim varlen, clow, ccc, skipflag
    skipflag = 0
    ccc =""
    varlen = LenB(binstr)
    For i = 1 To varlen
        If skipflag = 0 Then
            clow = MidB(binstr, i, 1)
            If AscB(clow) > 127 Then
                ccc = ccc & Chr(AscW(MidB(binstr, i + 1, 1) & clow))
                skipflag = 1
            Else
                ccc = ccc & Chr(AscB(clow))
            End If
        Else
            skipflag = 0
        End If
    Next
    bin2str = ccc
End FunctionFunction str2bin(Str)
    For i = 1 To Len(Str)
        str2bin = str2bin & ChrB(Asc(Mid(Str, i, 1)))
    Next
End FunctionFunction GetFileName(Str, Path, savtype)
    Set fs = Server.CreateObject("Scripting.FileSystemObject") '--日志--
w "GetFileName_Str=",Str
'--日志--
w "GetFileName_LenB(Str)=",LenB(Str)
'--日志--
w "GetFileName_str2bin(""filename="")=",str2bin("filename=")
'--日志--
w "GetFileName_InstrB(Str, str2bin(""filename=""))=",InstrB(Str, str2bin("filename="))    Str = RightB(Str, LenB(Str) - InstrB(Str, str2bin("filename=")) -9)    GetFileName =""
    FileName =""
    For i = LenB(Str) To 1 Step -1
        If MidB(Str, i, 1) = ChrB(Asc("\")) Then
            FileName = MidB(Str, i + 1, LenB(Str) - i - 1)
            Exit For
        End If
    Next '--日志--
w "GetFileName_FileName=",FileName
'--日志--
w "GetFileName_bin2str(FileName)=",bin2str(FileName)    If savtype = 0 And fs.FileExists(Path & bin2str(FileName)) = True Then
        hFileName = FileName
        rFileName =""
        For i = LenB(FileName) To 1 Step -1
            If MidB(FileName, i, 1) = ChrB(Asc(".")) Then
                hFileName = LeftB(FileName, i -1)
                rFileName = RightB(FileName, LenB(FileName) - i + 1)
                Exit For
            End If
        Next
        For i = 0 To 9999
            'hFileName   =   hFileName   &   str2bin(i)
            If fs.FileExists(Path & bin2str(hFileName) & i & bin2str(rFileName)) = False Then
                FileName = hFileName & str2bin(i) & rFileName
                Exit For
            End If
        Next
    End If
    Set fs = Nothing
    GetFileName = FileName
End Function
'==========接收
Dim filename
Path = Server.MapPath("./")
response.Write"本地路径:" & Path &"<br>" 
response.Write "<br>" 
'Response.Write Request
response.Write "<br>" 
filename = SaveFile("ImageSize", Path, 102400, 0)
If filename <>"*TooBig*" Then
    Response.Write" <br> <br>" & filename &" 已经上传"
Else
    Response.Write" <br> <br> 文件超出限制太大"
End If%>