The "pure ASP" file upload script I'm working with is giving me an error
Microsoft VBScript runtime error '800a0005'
Invalid procedure call or argument: 'MidB'
on this line (line 103 of include file clsUpload.asp):
mstrDelimiter = MidB(mbinData, 1, InStrB(1, mbinData, CRLF) - 1)
when I combine the File upload and the Database upload scripts on the same page. I thought it might have something to do with the instantiation of the class, and I've tried leaving the class established throughout the script, rather than setting it to 'nothing' and re establishing it, but that didn't make any difference. Any ideas?
The upload scripts work fine, as long as they are on separate pages, posted to separately by the first two forms on the page (below). The third form, however, isn't successful. Much appreciated!
(Code in full below)
Note: the "clsUpload.asp" and "clsField.asp" files were too large to post. They are, however available here: http://www.codeguru.com/dbfiles/get_file/upload_files_without_com_v2.zip?id=19297&lbl=UPLOAD_FILES_WITHOUT_COM_V2_ZIP
Form Page Below:
<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>
Form Processing Page (combined)
<!--#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>