gpt4 book ai didi

asp-classic - 在 ASP 脚本中组合文件和数据库上传时出错

转载 作者:行者123 更新时间:2023-12-04 02:52:56 25 4
gpt4 key购买 nike

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

最佳答案

问题出在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

关于asp-classic - 在 ASP 脚本中组合文件和数据库上传时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11678619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com