在ASP脚本中组合文件和数据库上载时出错

时间:2012-07-26 21:55:02

标签: asp-classic upload

我正在使用的“纯ASP”文件上传脚本给我一个错误

Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument: 'MidB' 

在这一行(包含文件clsUpload.asp的第103行):

mstrDelimiter = MidB(mbinData, 1, InStrB(1, mbinData, CRLF) - 1)

当我将文件上传和数据库上载脚本组合在同一页面上时。 我认为它可能与类的实例化有关,我已经尝试在整个脚本中建立类,而不是将其设置为“无”并重新建立它,但这没有任何区别。有任何想法吗?

上传脚本可以正常工作,只要它们在不同的页面上,由页面上的前两个表单(下面)单独发布。然而,第三种形式并不成功。 非常感激!

(以下完整的代码)

注意:“clsUpload.asp”和“clsField.asp”文件太大而无法发布。 它们可以在这里找到: http://www.codeguru.com/dbfiles/get_file/upload_files_without_com_v2.zip?id=19297&lbl=UPLOAD_FILES_WITHOUT_COM_V2_ZIP

下面的表单页面:

 <H2>To Database</H2>
<FORM name="a" id="a" method="post" encType="multipart/form-data" action="ToDatabase.asp">
<INPUT type="File" name="File1">
<INPUT name="Submit" type="submit" value="Upload">
 </FORM>

<H2>To File System</H2>
<FORM name="b" id="b" method="post" encType="multipart/form-data" action="ToFileSystem.asp">
<INPUT type="File" name="File1">
<INPUT name="Submit" type="submit" value="Upload">
</FORM>


<H2>To Both Database and File System</H2>
<FORM name="c" id="c" method="post" encType="multipart/form-data" action="ToDatabaseAndFileSystem.asp">
<INPUT type="File" name="File1">
<INPUT name="Submit" type="submit" value="Upload">
</FORM>


<HR>
<P>
This script provided to you by <A href="http://www.lewismoten.com">Lewis Moten</A>.
Please help me out and link back to my site from your own website, news groups,
postings on other websites, email, etc.
</P>

<p>Database file list below
</p>
<ol>
<%
Dim objUpload
Dim strFileName
Dim objConn
Dim objRs
Dim lngFileID


Set objConn = Server.CreateObject("ADODB.Connection")
Set objRs = Server.CreateObject("ADODB.Recordset")
objConn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" &     Server.MapPath("Files.mdb")
objRs.Open "SELECT * FROM Files", objConn, 2, 2

If Not (objRs.EOF And objRs.BOF) Then
objRs.MoveFirst
Do Until objRs.EOF = True
strFileName=objRs.Fields("FileName").Value
lngFileID = objRs.Fields("FileID").Value
%>
<li><A href="DataFile.asp?FileID=<%=lngFileID%>"><%=strFileName%></A></li>
<br />
<%
    objRs.MoveNext
Loop
Else
response.write("MsgBox """ & "There are not records in the recordset." & """<"&"/script>")
End If



objRs.Close
Set objRs = Nothing
Set objConn = Nothing
Set objUpload = Nothing
%>
</ol>

表格处理页面(合并)

 <!--#INCLUDE FILE="clsUpload.asp"-->
 <%
 Dim objUpload
 Dim strFileName
 Dim objConn
 Dim objRs
 Dim lngFileID
 Dim strPath


 '///database upload section - begin///
 ' Instantiate Upload Class
 Set objUpload = New clsUpload

 ' Grab the file name
 strFileName = objUpload.Fields("File1").FileName
 strLength = objUpload.Fields("File1").Length


 Set objConn = Server.CreateObject("ADODB.Connection")
 Set objRs = Server.CreateObject("ADODB.Recordset")

 ' Sometimes I personally have errors with one method on different servers, but the      other works.
 objConn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Files.mdb")
 'objConn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Files.mdb")

 'objRs.Open "Files", objConn, 3, 3
 objRs.Open "Files", objConn, 2, 2

 objRs.AddNew

 objRs.Fields("FileName").Value = objUpload.Fields("File1").FileName
 objRs.Fields("FileSize").Value = objUpload.Fields("File1").Length
 objRs.Fields("ContentType").Value = objUpload.Fields("File1").ContentType
 objRs.Fields("BinaryData").AppendChunk objUpload("File1").BLOB & ChrB(0)

 objRs.Update

 objRs.Close

 'objRs.Open "SELECT Max(FileID) AS ID FROM Files", objConn, 3, 3
 objRs.Open "SELECT Max(FileID) AS ID FROM Files", objConn, 2, 2
 lngFileID = objRs.Fields("ID").Value
 objRs.Close


 Set objRs = Nothing
 Set objConn = Nothing
 Set objUpload = Nothing
 %>
 File has been saved in database.<BR>
 <BR>
 View this file:<BR>
 <BR>
 <A href="DataFile.asp?FileID=<%=lngFileID%>"><%=strFileName%></A>

 '///database upload section - end///






 '///file server upload section - begin///
 <%
 ' Instantiate Upload Class
 Set objUpload = New clsUpload

 ' Grab the file name
 strFileName = objUpload.Fields("File1").FileName
 ' Compile path to save file to
 strPath = Server.MapPath("Uploads") & "\" & strFileName
 ' Save the binary data to the file system
 objUpload("File1").SaveAs strPath




 ' Release upload object from memory
 Set objUpload = Nothing

 MyVariable = strFileName
 Response.Write "<script type='text/javascript'>alert('" & MyVariable & "');</script>"
 %>
 File has been saved in file system.<BR>
 <BR>
 View this file:<BR>
 <BR>
 <A href="Uploads\<%=strFileName%>">Uploads\<%=strFileName%></A>

 <!-- /////////////////////////////////////////////////// -->


 '///file server upload section - begin///




 <ol>
 <%
 Set objConn = Server.CreateObject("ADODB.Connection")
 Set objRs = Server.CreateObject("ADODB.Recordset")
 objConn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Files.mdb")
 objRs.Open "SELECT * FROM Files", objConn, 2, 2

 If Not (objRs.EOF And objRs.BOF) Then
objRs.MoveFirst
Do Until objRs.EOF = True
 strFileName=objRs.Fields("FileName").Value
 lngFileID = objRs.Fields("FileID").Value%>
 <li><A href="DataFile.asp?FileID=<%=lngFileID%>"><%=strFileName%></A></li>
 <br />
 <%
    objRs.MoveNext
Loop
 Else
MsgBox "There are not records in the recordset."
 End If



 objRs.Close
 Set objRs = Nothing
 Set objConn = Nothing
 Set objUpload = Nothing
 %>
 </ol>

2 个答案:

答案 0 :(得分:1)

问题在于clsField.vbs文件

如果路径不包含“\”,则FileName字段保持空白:

我建议在if语句中添加else条件,如下所示:

    ' Parse File Name
    If Not InStrRev(pstrPath, "\") = 0 Then
        FileName = Mid(pstrPath, InStrRev(pstrPath, "\") + 1)
    else
        FileName = pstrPath
    End If

答案 1 :(得分:0)

此行失败:

mstrDelimiter = MidB(mbinData, 1, InStrB(1, mbinData, CRLF) - 1) 

可能的原因:

  • mbinData为零长度
  • mbinData不包含CRLF
  • mbinData以CRLF
  • 开头
  • 标识符CRLF不包含预期的字节序列

在您的案例中发现上述情况,您会发现问题。