3

我正在使用的“纯 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>
4

2 回答 2

2

问题出在 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
于 2012-07-27T09:29:06.623 回答
0

此行失败:

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

可能的原因:

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

找出以上哪项在您的情况下是正确的,您会发现问题所在。

于 2012-07-27T08:58:09.970 回答