经典的ASP文件上传问题

如何解决经典的ASP文件上传问题

我正在尝试上传一个 csv 文件,然后逐行读取它并将其传递到我的数据库。我在文件上传时遇到问题,我可以看到,每当我上传文件时,都会将一个额外的数字添加到我的 csv 列中,因此我的代码失败。我可以看到文件被保存在预期的位置,当我打开它时,我可以看到一个我从未添加过的额外数字。这可能是什么原因?

this is my csv file that got uploaded in server having that extra value

这是我上传 CSV 文件并读取它并使用循环的代码,我正在迭代 csv 文件中的值并将这些值存储在我的变量中,然后将这些值传递给存储在 DB 中的方法。>

<HTML>
<HEAD>
<!--#include file="clsUpload.asp"-->
<!-- #include file = "Bin/includes/GenFunctions.asp" -->
<!-- #include file = "Bin/includes/HeaderFooter.asp" -->
</HEAD>
<title>CMTL Entry File Upload</title>
<%showHeader%>
<BODY text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<FORM ACTION = "clsUploadtest.asp" ENCTYPE="multipart/form-data" METHOD="POST">
File Name: <INPUT TYPE=FILE NAME="txtFile"><P>
<INPUT TYPE = "SUBMIT" NAME="cmdSubmit" VALUE="SUBMIT">
</FORM><P>
<%

'Declare the form variables
Dim intRecordId
Dim strRecordId
Dim strAction
Dim strInputDate
Dim strPayer
Dim strAmount
Dim strTransType
Dim strPayee
Dim strAddRemarks
Dim strComments
Dim strAccNo
Dim strPolicyNo
Dim strBranchConfDate
Dim strConfBy
Dim strSheetUpdDate
Dim strMailUpdDate
Dim strUploadTime
Dim strUploadId
Dim strStatus
Dim strLastMdfdDate
Dim strLastMdfdId
Dim lineData
Dim  code
Dim name
Dim mail
Dim id
Dim price
Dim amount
Dim MyArray
Dim i 
i = 0

set obj = Server.CreateObject("AC_FI.mMTL")
If err.number <> 0 Then
    RaiseGenError objCMTL,"Error while creating the object "
    Response.End
end if

set o = new clsUpload
if o.Exists("cmdSubmit") then
'get client file name without path

sFileSplit = split(o.FileNameOf("txtFile"),"\")
sFile = sFileSplit(Ubound(sFileSplit))

o.FileInputName = "txtFile"
o.FileFullPath = Server.MapPath(".") & "\entry\" & sFile
o.save

 if o.Error = "" then
    response.write "Success. File saved to  " & o.FileFullPath  
 else
    response.write "Failed due to the following error: " & o.Error
end if

set fso = Server.CreateObject("Scripting.FileSystemObject") 
set fs = fso.OpenTextFile(Server.MapPath("entry/" & sFile),1,False)

 Do While Not fs.AtEndOfStream 
    lineData = fs.ReadLine
    'lineData = replace(lineData,chr(13),",")
    'lineData = replace(lineData,chr(34),"")
     MyArray = Split(lineData,")
     strRecordId=MyArray(0)
     strInputDate=MyArray(1)
     strPayer=MyArray(2)
     strAmount=MyArray(3)
     strTransType=MyArray(4)
     strPayee=MyArray(5) 
     strAddRemarks=MyArray(6)
     strComments=MyArray(7)
     strAccNo=MyArray(8)
     strPolicyNo=MyArray(9)
     strBranchConfDate=MyArray(10)
     strConfBy=MyArray(11)
     strSheetUpdDate=MyArray(12)
     strMailUpdDate=MyArray(13)
     strUploadTime=MyArray(14)
     strUploadId=MyArray(15)
     strStatus=MyArray(16)
      strRecordId       = convertNullString(strRecordId)
     strAction          = convertNullString(strAction)
     strInputDate       = convertNullDate(strInputDate)
    strPayer            = convertNullString(strPayer)
    strAmount           = convertNullString(strAmount)
    strTransType        = convertNullString(strTransType)
    strPayee            = convertNullString(strPayee)
    strAddRemarks       = convertNullString(strAddRemarks)
    strComments         = convertNullString(strComments)
    strAccNo            = convertNullString(strAccNo)
    strPolicyNo         = convertNullString(strPolicyNo)
    strBranchConfDate   = convertNullDate(strBranchConfDate)
    strConfBy           = convertNullString(strConfBy)
    strSheetUpdDate     = convertNullDate(strSheetUpdDate)
    strMailUpdDate      = convertNullDate(strMailUpdDate)
    strUploadTime       = convertNullDate(strUploadTime)
    strUploadId         = convertNullString(strUploadId)
    strStatus           = convertNullString(strStatus)
        intRecordId = obj.InsertData(strInputDate,strPayer,strAmount,strTransType,strPayee,strAddRemarks,_
                    strComments,strAccNo,strPolicyNo,strBranchConfDate,strConfBy,strSheetUpdDate,_
                    strMailUpdDate,strUploadTime,strUploadId,strStatus,pErrorcode)
    i=i+1
Loop 

fs.close() 
set fs = nothing
set fso = nothing
end if
set o = nothing

%>
<%showFooter%>
</BODY>
</HTML>

这是我用来上传文件的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
                                ' dictionary 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,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,CStrB("Content-Disposition"))
            
            ' Get an object name
            lnStartPosition = InstrB(lnDispositionPosition,CStrB("name=")) + 6
            lnEndPosition = InstrB(lnStartPosition,CStrB(""""))
            lsFieldName = CStrU(MidB(lnBytes,lnEndPosition - lnStartPosition))
            loField.FieldName = lsFieldName
            
            ' Get the location fo the file name.
            lnFileNamePosition = InstrB(lnBoundaryStart,CStrB("filename="))
            lnBoundaryEnd = InstrB(lnEndPosition,lnBoundaryBytes)
            
            'Test if object is a file
            If Not lnFileNamePosition = 0 And lnFileNamePosition < lnBoundaryEnd Then
            
                ' Parse Filename
                lnStartPosition = lnFileNamePosition + 10
                lnEndPosition =  InstrB(lnStartPosition,CStrB(""""))
                lsFileName = CStrU(MidB(lnBytes,lnEndPosition-lnStartPosition))
                loField.FileName = lsFileName               
                
                ' Parse Content-Type
                lnStartPosition = InstrB(lnEndPosition,CStrB("Content-Type:")) + 14
                lnEndPosition = InstrB(lnStartPosition,CStrB(vbCr))
                lsContentType = CStrU(MidB(lnBytes,lnEndPosition-lnStartPosition))
                loField.ContentType = lsContentType

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

                ' Parse Content
                lnStartPosition = InstrB(lnDispositionPosition,CStrB(vbCr)) + 4
                lnEndPosition = InstrB(lnStartPosition,lnBoundaryBytes) - 2
                lsValue = CStrU(MidB(lnBytes,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),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,1)))
        Next
    End Function
' ------------------------------------------------------------------------------
End Class
' ------------------------------------------------------------------------------
%>

您可以看到文件中添加了一个额外的值并且代码失败。每次上传文件时,我都不知道这个值来自哪里。我本地机器中的文件没有那个值。有人可以帮忙吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-