File 使用clsupload上载后,ASP Classic无法获取源文件的完整路径

File 使用clsupload上载后,ASP Classic无法获取源文件的完整路径,file,input,asp-classic,File,Input,Asp Classic,我正在使用上载文件 我希望获得上传文件的完整路径(路径来源,假设路径将不断更改)。我在回发期间尝试了以下代码,但无法获取完整的文件路径。请帮忙 <label class="col-sm-3 control-label">File Name : </label> <div class="col-sm-7" style="padding-top: 7px"> <input type=&quo

我正在使用
上载文件

我希望获得上传文件的完整路径(路径来源,假设路径将不断更改)。我在回发期间尝试了以下代码,但无法获取完整的文件路径。请帮忙

<label class="col-sm-3 control-label">File Name : </label>
<div class="col-sm-7" style="padding-top: 7px">
    <input type="FILE" name="txtFile" size="60" accept="text/plain">
</div>

<%
set o = new clsUpload
if o.Exists("cmdSubmit") then

    'get client file name
     sFile = o.FileNameOf("txtFile") 
     '====sFile will return Data20180513.txt
 
     response.write Server.MapPath(".")
     '==== This will only return D:\BRO\IQOR. 
     '==== The actual path should be D:\BRO\IQOR\database\attendanceData
     
     response.end
end if
%>
文件名:
文件层次结构

clsupload.asp 我正在使用以下类将文件保存到特定位置。但是,当我使用
上传文件时,如何获取文件的完整路径

<%
' ------------------------------------------------------------------------------
' Container of Field Properties
Class clsField
    Public FileName
    Public ContentType
    Public Value
    Public FieldName
    Public Length
    Public BinaryData
End Class
' ------------------------------------------------------------------------------
 Class clsUpload
' ------------------------------------------------------------------------------
    Private nFieldCount
    Private oFields()
    Private psFileFullPath
    Private psError
    Private psFileInputName
' ------------------------------------------------------------------------------
    Public Property Get Count()
        Count = nFieldCount
    End Property
' ------------------------------------------------------------------------------
    Public Default Property Get Field(ByRef asFieldName)
        Dim lnLength
        Dim lnIndex
    
        lnLength = UBound(oFields)
    
        If IsNumeric(asFieldName) Then
            If lnLength >= asFieldName And asFieldName > -1 Then
                Set Field = oFields(asFieldName)
            Else
                Set Field = New clsField
            End If
        Else
            For lnIndex = 0 To lnLength
                If LCase(oFields(lnIndex).FieldName) = LCase(asFieldName) Then
                    Set Field = oFields(lnIndex)
                    Exit Property
                End If
            Next
            Set Field = New clsField
        End If
    End Property
' ------------------------------------------------------------------------------
    Public Function Exists(ByRef avKeyIndex)
        Exists = Not IndexOf(avKeyIndex) = -1
    End Function
' ------------------------------------------------------------------------------
    Public Property Get ValueOf(ByRef avKeyIndex)
        Dim lnIndex
        lnIndex = IndexOf(avKeyIndex)
        if lnIndex = -1 Then Exit Property
        ValueOf = oFields(lnIndex).Value
    End Property
' ------------------------------------------------------------------------------
    Public Property Get FileNameOf(ByRef avKeyIndex)
        Dim lnIndex
        lnIndex = IndexOf(avKeyIndex)
        if lnIndex = -1 Then Exit Property
        FileNameOf = oFields(lnIndex).FileName
    End Property
' ------------------------------------------------------------------------------
    Public Property Get LengthOf(ByRef avKeyIndex)
        Dim lnIndex
        lnIndex = IndexOf(avKeyIndex)
        if lnIndex = -1 Then Exit Property
        LengthOf = oFields(lnIndex).Length
    End Property
' ------------------------------------------------------------------------------
    Public Property Get BinaryDataOf(ByRef avKeyIndex)
        Dim lnIndex
        lnIndex = IndexOf(avKeyIndex)
        if lnIndex = -1 Then Exit Property
        BinaryDataOf = oFields(lnIndex).BinaryData
    End Property
' ------------------------------------------------------------------------------
    Private Function IndexOf(ByVal avKeyIndex)
        Dim lnIndex
    
        If avKeyIndex = "" Then
            IndexOf = -1
        ElseIf IsNumeric(avKeyIndex) Then
            avKeyIndex = CLng(avKeyIndex)
            If nFieldCount > avKeyIndex And avKeyIndex > -1 Then
                IndexOf = avKeyIndex
            Else
                IndexOf = -1
            End If
        Else
            For lnIndex = 0 To nFieldCount - 1
                If LCase(oFields(lnIndex).FieldName) = LCase(avKeyIndex) Then
                    IndexOf = lnIndex
                    Exit Function
                End If
            Next
            IndexOf = -1
        End If
    End Function
' ------------------------------------------------------------------------------
Public Property Let FileFullPath(sValue)
    psFileFullPath = sValue
End Property

Public Property Get FileFullPath()
     FileFullPath = psFileFullPath 
End Property
' ------------------------------------------------------------------------------
Public Property Let FileInputName(sValue)
    psFileInputName = sValue
End Property
' --------------------  ----------------------------------------------------------
 Public Function Save()
    if psFileFullPath <> "" and psFileInputName <> "" then
        'Save to connectionless client side recordset, write to stream,
        'and persist stream.

        'would think you should be able to write directly to
        'stream without recordset, but I could not get that to work

        On error resume next
        binData = o.BinaryDataOf(psFileInputName)

        set rs = server.createobject("ADODB.RECORDSET")
        rs.fields.append "FileName", 205, LenB(binData)
        rs.open
        rs.addnew
        rs.fields(0).AppendChunk binData 
    
        if err.number = 0 then
            set objStream = Server.CreateObject("ADODB.Stream")
            objStream.Type  = 1
            objStream.Open
            objStream.Write rs.fields("FileName").value 
            objStream.SaveToFile psFileFullPath, 2
            objStream.close
            set objStream = Nothing

        ENd if
        rs.close
        set rs = nothing
        psError = Err.Description
else
        psError = "One or more required properties (FileFullPath and/or 
FileInputName) not set"

  End If


End Function

Public Property Get Error()
    Error = psError
End Property


' ------------------------------------------------------------------------------
    Public Property Get ContentTypeOf(ByRef avKeyIndex)
        Dim lnIndex
        lnIndex = IndexOf(avKeyIndex)
        if lnIndex = -1 Then Exit Property
        ContentTypeOf = oFields(lnIndex).ContentType
    End Property

' ------------------------------------------------------------------------------
    Private Sub Class_Terminate()
        Dim lnIndex
        For lnIndex = 0 To nFieldCount - 1
            Set oFields(0) = Nothing
        Next
    End Sub
' ------------------------------------------------------------------------------
    Private Sub Class_Initialize()
    
        Dim lnBytes             ' Bytes received from the client
        Dim lnByteCount         ' Number of bytes received
        Dim lnStartPosition     ' Position at which content begins
        Dim lnEndPosition       ' Position at which content ends
    
        Dim loDic               ' Contains properties of each
                                ' specific field
                                ' Local dictionary object(s) 
                                ' to be appended to class-scope
                                ' dictioary object.
                            
        Dim lnBoundaryBytes     ' Bytes contained within the current boundary
        Dim lnBoundaryStart     ' Position at which the current boundary begins
                            ' within the lnBytes binary data.
        Dim lnBoundaryEnd       ' Position at which the current boundary ends
                            ' within the lnBytes binary data.
        Dim lnDispositionPosition
    
        Dim lsFieldName         ' Name of the current field being parsed from
                            ' Binary Data
        Dim lsFileName          ' Name of the file within the current boundary
        Dim lnFileNamePosition  ' Location of file name within current boundary
        Dim loField             ' clsField Object
        Dim lsValue             ' Value of the current field
        Dim lsContentType       ' ContentType of the binary file (MIME Type)
    
        ' Initialize Fields
        nFieldCount = 0
        ReDim oFields(-1)
    
        ' Read the bytes (binary data) into memory  
        lnByteCount = Request.TotalBytes
        lnBytes = Request.BinaryRead(lnByteCount)
    
        'Get the lnBoundaryBytes
        lnStartPosition = 1
        lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(vbCr))
    
        If lnEndPosition >= lnStartPosition Then
            lnBoundaryBytes = MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition)
        End If
    
        lnBoundaryStart = InstrB(1, lnBytes, lnBoundaryBytes)
    
    
        ' Loop until the BoundaryBytes begin with "--"
        Do Until (lnBoundaryStart = InstrB(lnBytes, lnBoundaryBytes & CStrB("--")))
    
            ' All data within this boundary is stored within a local dictionary
            ' to be appended to the class-scope dictionary.
        
            ReDim Preserve oFields(nFieldCount)
            nFieldCount = nFieldCount + 1
        
            Set loField = New clsField

            lnDispositionPosition = InstrB(lnBoundaryStart, lnBytes, CStrB("Content-Disposition"))
        
            ' Get an object name
            lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB("name=")) + 6
            lnEndPosition = InstrB(lnStartPosition, lnBytes, CStrB(""""))
            lsFieldName = CStrU(MidB(lnBytes, lnStartPosition, lnEndPosition - lnStartPosition))
            loField.FieldName = lsFieldName
        
            ' Get the location fo the file name.
            lnFileNamePosition = InstrB(lnBoundaryStart, lnBytes, CStrB("filename="))
            lnBoundaryEnd = InstrB(lnEndPosition, lnBytes, lnBoundaryBytes)
        
            'Test if object is a file
            If Not lnFileNamePosition = 0 And lnFileNamePosition < lnBoundaryEnd Then
        
                ' Parse Filename
                lnStartPosition = lnFileNamePosition + 10
                lnEndPosition =  InstrB(lnStartPosition, lnBytes, CStrB(""""))
                lsFileName = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
                loField.FileName = lsFileName               
            
                ' Parse Content-Type
                lnStartPosition = InstrB(lnEndPosition,lnBytes,CStrB("Content-Type:")) + 14
                lnEndPosition = InstrB(lnStartPosition,lnBytes,CStrB(vbCr))
                lsContentType = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
                loField.ContentType = lsContentType

                ' Parse Content
                lnStartPosition = lnEndPosition + 4
                lnEndPosition = InstrB(lnStartPosition,lnBytes,lnBoundaryBytes)-2
                lsValue = MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition)
                loField.BinaryData = lsValue & CStrB(vbNull)
                loField.Length = LenB(lsValue)
            Else

                ' Parse Content
                lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB(vbCr)) + 4
                lnEndPosition = InstrB(lnStartPosition, lnBytes, lnBoundaryBytes) - 2
                lsValue = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition))
                loField.Value = lsValue
                loField.Length = Len(lsValue)
            End If

            Set oFields(UBound(oFields)) = loField

            'Loop to next object
            lnBoundaryStart = InstrB(lnBoundaryStart + LenB(lnBoundaryBytes), lnBytes, lnBoundaryBytes)
        
            Set loField = Nothing
        
        Loop

    End Sub
' ------------------------------------------------------------------------------
    Private Function CStrU(ByRef psByteString)
        Dim lnLength
        Dim lnPosition
        lnLength = LenB(psByteString)
        For lnPosition = 1 To lnLength
            CStrU = CStrU & Chr(AscB(MidB(psByteString, lnPosition, 1)))
        Next
    End Function
' ------------------------------------------------------------------------------
    Private Function CStrB(ByRef psUnicodeString)
        Dim lnLength
        Dim lnPosition
        lnLength = Len(psUnicodeString)
        For lnPosition = 1 To lnLength
            CStrB = CStrB & ChrB(AscB(Mid(psUnicodeString, lnPosition, 1)))
        Next
    End Function
' ------------------------------------------------------------------------------
End Class
' ------------------------------------------------------------------------------
%>
=asFieldName和asFieldName>-1然后
设置字段=字段(asFieldName)
其他的
设置字段=新的clsField
如果结束
其他的
对于lnIndex=0到lnLength
如果LCase(oFields(lnIndex).FieldName)=LCase(asFieldName),则
设置字段=oFields(lnIndex)
退出属性
如果结束
下一个
设置字段=新的clsField
如果结束
端属性
' ------------------------------------------------------------------------------
存在公共函数(ByRef avKeyIndex)
Exists=非索引of(avKeyIndex)=-1
端函数
' ------------------------------------------------------------------------------
公共财产获取价值(ByRef avKeyIndex)
暗淡指数
lnIndex=IndexOf(avKeyIndex)
如果lnIndex=-1,则退出属性
ValueOf=OFIELD(LNIDEX)。值
端属性
' ------------------------------------------------------------------------------
公共属性获取文件名(ByRef avKeyIndex)
暗淡指数
lnIndex=IndexOf(avKeyIndex)
如果lnIndex=-1,则退出属性
FileNameOf=oFields(lnIndex).FileName
端属性
' ------------------------------------------------------------------------------
公共属性Get LengthOf(ByRef avKeyIndex)
暗淡指数
lnIndex=IndexOf(avKeyIndex)
如果lnIndex=-1,则退出属性
LengthOf=长度(lnIndex)。长度
端属性
' ------------------------------------------------------------------------------
公共属性Get BinaryDataOf(ByRef avKeyIndex)
暗淡指数
lnIndex=IndexOf(avKeyIndex)
如果lnIndex=-1,则退出属性
BinaryDataOf=oFields(lnIndex).BinaryData
端属性
' ------------------------------------------------------------------------------
私有函数索引of(ByVal avKeyIndex)
暗淡指数
如果avKeyIndex=“”,则
IndexOf=-1
ElseIf是数字(avKeyIndex)那么
avKeyIndex=CLng(avKeyIndex)
如果nFieldCount>avKeyIndex和avKeyIndex>1,则
IndexOf=avKeyIndex
其他的
IndexOf=-1
如果结束
其他的
对于lnIndex=0,nFieldCount-1
如果LCase(of ields(lnIndex).FieldName)=LCase(avKeyIndex),则
IndexOf=lnIndex
退出功能
如果结束
下一个
IndexOf=-1
如果结束
端函数
' ------------------------------------------------------------------------------
公共属性Let FileFullPath(S值)
psFileFullPath=s值
端属性
公共属性Get FileFullPath()
FileFullPath=psFileFullPath
端属性
' ------------------------------------------------------------------------------
公共属性Let FileInputName(S值)
psFileInputName=s值
端属性
' --------------------  ----------------------------------------------------------
公共函数Save()
如果psFileFullPath“”和psFileInputName“”,则
'保存到无连接客户端记录集,写入流,
"坚持,。
“我想你应该可以直接写信给
“没有记录集的流,但我无法让它工作
出错时继续下一步
binData=o.BinaryDataOf(psFileInputName)
set rs=server.createobject(“ADODB.RECORDSET”)
rs.fields.append“FileName”,205,LenB(binData)
rs公开赛
空记录
rs.fields(0).AppendChunk binData
如果err.number=0,则
设置objStream=Server.CreateObject(“ADODB.Stream”)
objStream.Type=1
对象流。打开
objStream.Write rs.fields(“文件名”).value
objStream.SaveToFile psFileFullPath,2
objStream.close
设置objStream=Nothing
如果结束
克洛斯
设置rs=无
psError=错误描述
其他的
psError=“一个或多个必需的属性(FileFullPath和/或
FileInputName)未设置“
如果结束
端函数
公共属性获取错误()
错误=psError
端属性
' ------------------------------------------------------------------------------
公共属性获取ContentTypeOf(ByRef avKeyIndex)
暗淡指数
lnIndex=IndexOf(avKeyIndex)
如果lnIndex=-1,则退出属性
ContentTypeOf=oFields(lnIndex)。ContentType
端属性
' ------------------------------------------------------------------------------
私有子类_Terminate()
暗淡指数
对于lnIndex=0,nFieldCount-1
字段集(0)=无
下一个
端接头
' ------------------------------------------------------------------------------
私有子类_Initialize()
Dim lnBytes从客户端接收的字节数
Dim lnByteCount'接收的字节数
Dim lnStartPosition“内容开始的位置
Dim lnEndPosition内容结束的位置
“Dim loDic”包含每个
'特定字段
“本地d