其中类B的代码如下:
--------------------------------------------------
Private p_MaxSize, p_FileType, p_SavePath, p_AutoSave, p_Error
Private strDate, lngTime, strMSG, strFileName
Public FormItem, FileItem
Public objForm As Object, binForm As Object, binItem As Object
Public Sub OnStartPage(stContext As ScriptingContext)
    Set Response = stContext.Response
    Set Server = stContext.Server
    Set Request = stContext.Request
    Set Session = stContext.Session    Init
End SubPublic Sub OnEndPage()
    Rem to do something
    Set Response = Nothing
    Set Server = Nothing
    Set Request = Nothing
    Set Session = Nothing
    
    objForm.RemoveAll
    Set objForm = Nothing
    Set binItem = Nothing
    binForm.Close
    Set binForm = Nothing
End SubPublic Property Get Version()
    Version = "Upload File For SunGo!"
End PropertyPublic Property Get Error()
    Error = p_Error
End PropertyPublic Property Get MaxSize()
    MaxSize = p_MaxSize
End PropertyPublic Property Let MaxSize(ByVal lngSize As Variant)
    If IsNumeric(lngSize) Then
        p_MaxSize = CLng(lngSize)
    End If
End PropertyPublic Property Get FileType()
    FileType = p_FileType
End Property
Public Property Let FileType(ByVal strType As Variant)
    p_FileType = strType
End PropertyPublic Property Get SavePath()
    SavePath = p_SavePath
End Property

解决方案 »

  1.   

    Public Property Let SavePath(ByVal strPath As Variant)
        p_SavePath = Replace(strPath, Chr(0), "")
    End PropertyPublic Property Get AutoSave()
        AutoSave = p_AutoSave
    End PropertyPublic Property Let AutoSave(ByVal Flag As Variant)
        Select Case Flag
            Case 0:
            Case 1:
            Case 2:
            Case False: Flag = 2
            Case Else: Flag = 0
        End Select
        p_AutoSave = Flag
    End PropertyPublic Property Get MSG()
        MSG = strMSG ''取得出错信息-
    End PropertyPublic Property Get FileName()
        FileName = strFileName
    End PropertyPublic Property Let FileName(ByVal strName As Variant)
        strFileName = strName
    End PropertyPublic Function Init()
        p_Error = -1
        p_MaxSize = 1536000
        p_FileType = "jpg/gif"
        p_SavePath = "/images/" ''设置上传图片的保存位置
        p_AutoSave = 0
        strDate = Replace(CStr(Date), "-", "")
        lngTime = CLng(Timer() * 1000)
        Set binForm = Server.CreateObject("ADODB.Stream")
        Set binItem = Server.CreateObject("ADODB.Stream")
        Set objForm = Server.CreateObject("Scripting.Dictionary")
        objForm.CompareMode = 1
    End FunctionPublic Sub Start()
        If p_Error = -1 Then
            p_Error = 0
        Else
            Exit Sub
        End If
        Dim lngRequestSize, binRequestData, strFormItem, strFileItem
        Const strSplit = "'"">"
        lngRequestSize = Request.TotalBytes
        If lngRequestSize < 1 Then
            p_Error = 4
            Exit Sub
        End If
        binRequestData = Request.BinaryRead(lngRequestSize)
        binForm.Type = 1
        binForm.Open
        binForm.Write binRequestData    Dim bCrLf, strSeparator, intSeparator
        bCrLf = ChrB(13) & ChrB(10)    intSeparator = InStrB(1, binRequestData, bCrLf) - 1
        strSeparator = LeftB(binRequestData, intSeparator)    Dim p_start, p_end, strItem, strInam, intTemp, strTemp
        Dim strFtyp, strFnam, strFext, lngFsiz
        p_start = intSeparator + 2
        Do
            p_end = InStrB(p_start, binRequestData, bCrLf & bCrLf) + 3
            binItem.Type = 1
            binItem.Open
            binForm.Position = p_start
            binForm.CopyTo binItem, p_end - p_start
            binItem.Position = 0
            binItem.Type = 2
            binItem.Charset = "gb2312"
            strItem = binItem.ReadText
            binItem.Close        p_start = p_end
            p_end = InStrB(p_start, binRequestData, strSeparator) - 1
            binItem.Type = 1
            binItem.Open
            binForm.Position = p_start
            lngFsiz = p_end - p_start - 2
            binForm.CopyTo binItem, lngFsiz        intTemp = InStr(39, strItem, """")
            strInam = Mid(strItem, 39, intTemp - 39)        If InStr(intTemp, strItem, "filename=""") <> 0 Then
            If Not objForm.Exists(strInam & "_From") Then
                strFileItem = strFileItem & strSplit & strInam
                If binItem.Size <> 0 Then
                    intTemp = intTemp + 13
                    strFtyp = Mid(strItem, InStr(intTemp, strItem, "Content-Type: ") + 14)
                    strTemp = Mid(strItem, intTemp, InStr(intTemp, strItem, """") - intTemp)
                    intTemp = InStrRev(strTemp, "\")
                    strFnam = Mid(strTemp, intTemp + 1)
                    objForm.Add strInam & "_Type", strFtyp
                    objForm.Add strInam & "_Name", strFnam
                    objForm.Add strInam & "_Path", Left(strTemp, intTemp)
                    objForm.Add strInam & "_Size", lngFsiz
                    If InStr(intTemp, strTemp, ".") <> 0 Then
                        strFext = Mid(strTemp, InStrRev(strTemp, ".") + 1)
                    Else
                        strFext = ""
                    End If
                    If Left(strFtyp, 6) = "image/" Then
                        binItem.Position = 0
                        binItem.Type = 1
                        strTemp = binItem.Read(10)
                        If StrComp(strTemp, ChrB(255) & ChrB(216) & ChrB(255) & ChrB(224) & ChrB(0) & ChrB(16) & ChrB(74) & ChrB(70) & ChrB(73) & ChrB(70), 0) = 0 Then
                            If LCase(strFext) <> "jpg" Then strFext = "jpg"
                            binItem.Position = 3
                            Do While Not binItem.EOS
                                Do
                                    intTemp = AscB(binItem.Read(1))
                                Loop While intTemp = 255 And Not binItem.EOS
                                If intTemp < 192 Or intTemp > 195 Then
                                    binItem.Read (Bin2Val(binItem.Read(2)) - 2)
                                Else
                                    Exit Do
                                End If
                                Do
                                    intTemp = AscB(binItem.Read(1))
                                Loop While intTemp < 255 And Not binItem.EOS
                            Loop
                            binItem.Read (3)
                            objForm.Add strInam & "_Height", Bin2Val(binItem.Read(2))
                            objForm.Add strInam & "_Width", Bin2Val(binItem.Read(2))
                        ElseIf StrComp(LeftB(strTemp, 8), ChrB(137) & ChrB(80) & ChrB(78) & ChrB(71) & ChrB(13) & ChrB(10) & ChrB(26) & ChrB(10), 0) = 0 Then
                            If LCase(strFext) <> "png" Then strFext = "png"
                            binItem.Position = 18
                            objForm.Add strInam & "_Width", Bin2Val(binItem.Read(2))
                            binItem.Read (2)
                            objForm.Add strInam & "_Height", Bin2Val(binItem.Read(2))
                        ElseIf StrComp(LeftB(strTemp, 6), ChrB(71) & ChrB(73) & ChrB(70) & ChrB(56) & ChrB(57) & ChrB(97), 0) = 0 Or StrComp(LeftB(strTemp, 6), ChrB(71) & ChrB(73) & ChrB(70) & ChrB(56) & ChrB(55) & ChrB(97), 0) = 0 Then
                            If LCase(strFext) <> "gif" Then strFext = "gif"
                            binItem.Position = 6
                            objForm.Add strInam & "_Width", BinVal2(binItem.Read(2))
                            objForm.Add strInam & "_Height", BinVal2(binItem.Read(2))
                        ElseIf StrComp(LeftB(strTemp, 2), ChrB(66) & ChrB(77), 0) = 0 Then
                            If LCase(strFext) <> "bmp" Then strFext = "bmp"
                            binItem.Position = 18
                            objForm.Add strInam & "_Width", BinVal2(binItem.Read(4))
                            objForm.Add strInam & "_Height", BinVal2(binItem.Read(4))
                        End If
                    End If
                    objForm.Add strInam & "_Ext", strFext
                    objForm.Add strInam & "_From", p_start
                    intTemp = GetFerr(lngFsiz, strFext)
                    If p_AutoSave <> 2 Then
                        objForm.Add strInam & "_Err", intTemp
                        If intTemp = 0 Then
                            If p_AutoSave = 0 Then
                                strFnam = "v3-" & GetTimeStr() & "-" & strDate & lngTime & "-" & GetTimeStr()
                                If strFext <> "" Then strFnam = strFnam & "." & strFext
                            End If
                            binItem.SaveToFile Server.MapPath(p_SavePath & strFnam), 2
                            objForm.Add strInam, strFnam
                            strFileName = strFnam
                        End If
                    End If
                Else
                    objForm.Add strInam & "_Err", -1
                End If
            End If
            Else
                binItem.Position = 0
                binItem.Type = 2
                binItem.Charset = "gb2312"
                strTemp = binItem.ReadText
                If objForm.Exists(strInam) Then
                    objForm(strInam) = objForm(strInam) & "," & strTemp
                Else
                    strFormItem = strFormItem & strSplit & strInam
                    objForm.Add strInam, strTemp
                End If
            End If        binItem.Close
            p_start = p_end + intSeparator + 2
        Loop Until p_start + 3 > lngRequestSize
        FormItem = Split(strFormItem, strSplit)
        FileItem = Split(strFileItem, strSplit)
    End Sub
      

  2.   

    Private Function GetTimeStr()
        Server.ScriptTimeout = 5
        Dim strlen, strout, rndid
        strlen = 0
        strout = ""
        Do While strlen < 6
            Randomize
            rndid = Int(Rnd * 74) + 48
            If (rndid >= 49 And rndid <= 57) Or (rndid >= 97 And rndid <= 122) Or (rndid >= 65 And rndid <= 90) Then
                strout = strout & Chr(rndid)
                strlen = strlen + 1
            End If
        Loop
        GetTimeStr = strout
    End FunctionPrivate Function GetFerr(ByVal lngFsiz As Variant, ByVal strFext As Variant)
        Dim intFerr
        intFerr = 0
        If lngFsiz > p_MaxSize And p_MaxSize > 0 Then
            If p_Error = 0 Or p_Error = 2 Then p_Error = p_Error + 1
            intFerr = intFerr + 1
        End If
        If InStr(1, LCase("/" & p_FileType & "/"), LCase("/" & strFext & "/")) = 0 And p_FileType <> "" Then
            If p_Error < 2 Then p_Error = p_Error + 2
            intFerr = intFerr + 2
        End If
        GetFerr = intFerr
    End FunctionPublic Function Save(ByVal Item As Variant, ByVal strFnam As Variant)
        Save = False
        If objForm.Exists(Item & "_From") Then
            Dim intFerr, strFext
            strFext = objForm(Item & "_Ext")
            intFerr = GetFerr(objForm(Item & "_Size"), strFext)
            If objForm.Exists(Item & "_Err") Then
                If intFerr = 0 Then
                    objForm(Item & "_Err") = 0
                End If
            Else
                objForm.Add Item & "_Err", intFerr
            End If
            If intFerr <> 0 Then Exit Function
            If VarType(strFnam) = 2 Then
                Select Case strFnam
                    Case 0: strFnam = "v3-" & GetTimeStr() & "-" & strDate & lngTime & "-" & GetTimeStr()
                        If strFext <> "" Then strFnam = strFnam & "." & strFext
                    Case 1: strFnam = objForm(Item & "_Name")
                    Case 2: strFnam = strFileName
                End Select
            End If
            binItem.Type = 1
            binItem.Open
            binForm.Position = objForm(Item & "_From")
            binForm.CopyTo binItem, objForm(Item & "_Size")
            binItem.SaveToFile Server.MapPath(p_SavePath & strFnam), 2
            binItem.Close
            If objForm.Exists(Item) Then
                objForm(Item) = strFnam
            Else
                objForm.Add Item, strFnam
            End If
            strFileName = strFnam
            Save = True
            
            
            ''额外增加一个按照指定宽和高进行保存---------------
            On Error Resume Next
            Dim objJpeg As ASPJPEGLib.ASPJpeg, Path As String
            Set objJpeg = New ASPJPEGLib.ASPJpeg
            
            With objJpeg
                .Open Server.MapPath(p_SavePath & strFnam)
            End With
            ' 打开目标图片
            
            objJpeg.Width = objJpeg.OriginalWidth
            objJpeg.Height = objJpeg.OriginalHeight
            
            If objJpeg.OriginalWidth > 500 Then
                objJpeg.Width = 500
                objJpeg.Height = objJpeg.OriginalHeight * (500 / objJpeg.OriginalWidth)
            End If
            objJpeg.Save Server.MapPath(p_SavePath & strFnam)
            Set objJpeg = Nothing
        End If
    End FunctionPublic Function GetData(ByVal Item As Variant)
        GetData = ""
        If objForm.Exists(Item & "_From") Then
            If GetFerr(objForm(Item & "_Size"), objForm(Item & "_Ext")) <> 0 Then Exit Function
            binForm.Position = objForm(Item & "_From")
            GetData = binFormStream.Read(objForm(Item & "_Size"))
        End If
    End FunctionPublic Function Form(ByVal Item As Variant)
        If objForm.Exists(Item) Then
            Form = objForm(Item)
        Else
            Form = ""
        End If
    End FunctionPrivate Function BinVal2(ByVal bin As Variant)
        Dim lngValue, i
        lngValue = 0
        For i = LenB(bin) To 1 Step -1
            lngValue = lngValue * 256 + AscB(MidB(bin, i, 1))
        Next
        BinVal2 = lngValue
    End FunctionPrivate Function Bin2Val(ByVal bin As Variant)
        Dim lngValue, i
        lngValue = 0
        For i = 1 To LenB(bin)
            lngValue = lngValue * 256 + AscB(MidB(bin, i, 1))
        Next
        Bin2Val = lngValue
    End FunctionRem 扩展功能------------
    Public Function ZoomPic(ByVal foldername As String, ByVal FileName As String) As Boolean
        ZoomPic = True
        On Error Resume Next
        Dim Jpeg As ASPJPEGLib.ASPJpeg, Path As String
        Set Jpeg = New ASPJPEGLib.ASPJpeg
        
        With Jpeg
            .Open foldername & "\" & FileName
        End With
        
        If Jpeg.Width > 200 And (Jpeg.Width / Jpeg.Height) > 1.5 Then
            Jpeg.Height = 90
            Jpeg.Width = 100
            
        ElseIf Jpeg.Width > 200 And ((Jpeg.Width / Jpeg.Height) > 1 And (Jpeg.Width / Jpeg.Height) <= 1.5) Then
            Jpeg.Height = 100
            Jpeg.Width = Jpeg.OriginalWidth * (100 / Jpeg.OriginalHeight)
            
        ElseIf Jpeg.Height > 200 And (Jpeg.Height / Jpeg.Width) > 1.5 Then
            Jpeg.Width = 90
            Jpeg.Height = 100
            
        ElseIf Jpeg.Height > 200 And ((Jpeg.Height / Jpeg.Width) > 1 And (Jpeg.Height / Jpeg.Width) <= 1.5) Then
            Jpeg.Width = 100
            Jpeg.Height = Jpeg.OriginalHeight * (100 / Jpeg.OriginalWidth)
            
        Else
            Jpeg.Width = Jpeg.OriginalWidth
            Jpeg.Height = Jpeg.OriginalHeight
        End If
        
        Jpeg.Save foldername & "\_" & FileName
        
        If Err Then
            strMSG = "生产缩略图失败:[" & Err.Description & "]…"
            Err.Clear
            ZoomPic = False
        End If
        Jpeg.Close: Set Jpeg = Nothing
    End Function''=======以下为上传的图片添加水印=======
    Public Function WaterMark(ByVal fpath As String) As Boolean
        WaterMark = True
        On Error Resume Next
        Dim Jpeg As ASPJpeg
        ' 建立实例
        Set Jpeg = New ASPJpeg
        ' 打开目标图片
        Jpeg.Open Server.MapPath(fpath)
        ' 添加文字水印
        'Jpeg.Canvas.Font.Color = "red"
        Jpeg.Canvas.Font.Family = "宋体"
        Jpeg.Canvas.Font.Bold = True
        
        With Jpeg.Canvas
             .Print Jpeg.OriginalWidth - Jpeg.OriginalWidth \ 3, Jpeg.OriginalHeight - Jpeg.OriginalHeight \ 3, SiteName
        End With    ' 保存文件
        Jpeg.Save Server.MapPath(fpath)
        ' 注销对象
        Jpeg.Close: Set Jpeg = Nothing
        
        If Err Then
            strMSG = "为图片添加水印失败:[" & Err.Description & Err.Source & "]…"
            Err.Clear
            WaterMark = False
        End If
    End Function
    -------------------------------------------
      

  3.   

    类A里如下调用:
    Private strMSG, intRdCount, aryMemberInfoPublic Sub OnStartPage(stContext As ScriptingContext)
        Set Response = stContext.Response
        Set Server = stContext.Server
        Set Session = stContext.Session
        Set Request = stContext.Request
        If IsConn = False Then
            Response.Write DbConnectionErr
            OnEndPage
            Response.End
            Exit Sub
        End If
    End SubPublic Sub OnEndPage()
        Rem to do something
        Set Response = Nothing
        Set Server = Nothing
        Set Session = Nothing
        Set Request = Nothing
    End SubPublic Property Get MemId()
        MemId = intMemId
    End PropertyPublic Property Get Uame()
        Uame = strUame
    End PropertyPublic Property Get Upwd()
        Upwd = strUpwd
    End PropertyPublic Property Get RealName()
        RealName = strRealName
    End PropertyPublic Property Get Sex()
        Sex = strSex
    End PropertyPublic Property Get BirthDay()
        BirthDay = dtBirthDay
    End PropertyPublic Property Get AddrHome()
        AddrHome = strAddrHome
    End PropertyPublic Property Get AddrHere()
        AddrHere = strAddrHere
    End PropertyPublic Property Get Phone()
        Phone = strPhone
    End PropertyPublic Property Get DepartmentId()
        DepartmentId = intDepartmentId
    End PropertyPublic Property Get Flag()
        Flag = intFlag
    End PropertyPublic Property Get MaxPuserNum()
        MaxPuserNum = intMaxPuserNum
    End PropertyPublic Property Get Intro()
        Intro = strIntro
    End PropertyPublic Property Get Pass()
        Pass = intPass
    End PropertyPublic Property Get LastLogin()
        LastLogin = strLastLogin
    End PropertyPublic Property Get Uphotos()
        Uphotos = strUphotos
    End PropertyPublic Property Get Uphotob()
        Uphotob = strUphotob
    End PropertyPublic Property Get Degree()
        Degree = strDegree
    End PropertyPublic Property Get AdminDepart()
        AdminDepart = strAdminDepart
    End PropertyPublic Property Get MSG()
        MSG = strMSG
    End PropertyPublic Property Get RdCount()
        RdCount = intRdCount
    End PropertyPublic Property Get MemberInfo()
        MemberInfo = aryMemberInfo
    End PropertyPublic Function hh()
        Dim myrequest As UpLoadClass, stContext As ScriptingContext
        Set myrequest = New UpLoadClass
        'myrequest.OnStartPage stContext
        Response.Write myrequest.SavePath & "...."
        Set myrequest = Nothing
    End Function-------------------------
    编译通过但是在asp里如下执行的时候出现"未设置对象变量或引用"错误:
    set objMember=Server.CreateObject("CRM.Member")
    objMember.hh
    set objMember=nothing大虾,怎么办啊