Link to home
Start Free TrialLog in
Avatar of cookiejest
cookiejest

asked on

pure asp upload troubles...

I am using pure asp upload to upload files to a folder on the server and then form fields to a database. Here is my script that does the uploading:

<%
<!-- #include file="upload.asp" -->
'Dimension variables
Dim adoCon              'Holds the Database Connection Object
Dim rs   'Holds the recordset for the new record to be added
Dim strSQL               'Holds the SQL query to query the database
Dim Uploader, File
Set Uploader = New FileUploader

' This starts the upload process
Uploader.Upload()

      ' Loop through the uploaded files
      For Each File In Uploader.Files.Items
      
                  ' Save the file
                  File.SaveToDisk "C:\Inetpub\wwwroot\flashsystem\flash\"

'Create an ADO connection object
Set adoCon = Server.CreateObject("ADODB.Connection")

'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("flashdb.mdb")

'Create an ADO recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT tblFlashinfo.Author, tblFlashinfo.Author_Link, tblFlashinfo.Title, tblFlashinfo.Entry_Type, tblFlashinfo.Height, tblFlashinfo.Width, tblFlashinfo.Description, tblFlashinfo.File_Name FROM tblFlashinfo;"

'Set the cursor type we are using so we can navigate through the recordset
rs.CursorType = 2

'Set the lock type so that the record is locked by ADO when it is updated
rs.LockType = 3

'Open the recordset with the SQL query
rs.Open strSQL, adoCon

'Tell the recordset we are adding a new record to it
rs.AddNew

'Add a new record to the recordset
rs.Fields("Author") =  Uploader.form("Author")
rs.Fields("Author_Link") = Uploader.form("Author_Link")
rs.Fields("Title") = Uploader.form("Title")
rs.Fields("Entry_Type") = Uploader.form("Entry_Type")
rs.Fields("Height") = Uploader.form("Height")
rs.Fields("Width") = Uploader.form("Width")
rs.Fields("Description") = Uploader.form("Description")
rs("file_Name")    = File.FileName

'Write the updated recordset to the database
rs.Update            


'Reset server objects
rs.Close
Set rs = Nothing
Set adoCon = Nothing
      Next
%>

I get there error message:

Microsoft VBScript runtime  error '800a01fa'

Class not defined: 'FileUploader'

/flashsystem/sendflash.asp, line 12

I dont understand as i thought it was defined in the include upload.asp.

The upload.asp looks like this:

<%
'***************************************
' File:        Upload.asp
' Author: Jacob "Beezle" Gilley
' Email:  avis7@airmail.net
' Date:   12/07/2000
' Comments: The code for the Upload, CByteString,
'                  CWideString      subroutines was originally
'                  written by Philippe Collignon...or so
'                  he claims. Also, I am not responsible
'                  for any ill effects this script may
'                  cause and provide this script "AS IS".
'                  Enjoy!
'****************************************

Class FileUploader
      Public  Files
      Private mcolFormElem

      Private Sub Class_Initialize()
            Set Files = Server.CreateObject("Scripting.Dictionary")
            Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
      End Sub
      
      Private Sub Class_Terminate()
            If IsObject(Files) Then
                  Files.RemoveAll()
                  Set Files = Nothing
            End If
            If IsObject(mcolFormElem) Then
                  mcolFormElem.RemoveAll()
                  Set mcolFormElem = Nothing
            End If
      End Sub

      Public Property Get Form(sIndex)
            Form = ""
            If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
      End Property

      Public Default Sub Upload()
            Dim biData, sInputName
            Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
            Dim nPosFile, nPosBound

            biData = Request.BinaryRead(Request.TotalBytes)
            nPosBegin = 1
            nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
            
            If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
             
            vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
            nDataBoundPos = InstrB(1, biData, vDataBounds)
            
            Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
                  
                  nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
                  nPos = InstrB(nPos, biData, CByteString("name="))
                  nPosBegin = nPos + 6
                  nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
                  sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                  nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
                  nPosBound = InstrB(nPosEnd, biData, vDataBounds)
                  
                  If nPosFile <> 0 And  nPosFile < nPosBound Then
                        Dim oUploadFile, sFileName
                        Set oUploadFile = New UploadedFile
                        
                        nPosBegin = nPosFile + 10
                        nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
                        sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                        oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))

                        nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
                        nPosBegin = nPos + 14
                        nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
                        
                        oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                        
                        nPosBegin = nPosEnd+4
                        nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
                        oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
                        
                        If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
                  Else
                        nPos = InstrB(nPos, biData, CByteString(Chr(13)))
                        nPosBegin = nPos + 4
                        nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
                        If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
                  End If

                  nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
            Loop
      End Sub

      'String to byte string conversion
      Private Function CByteString(sString)
            Dim nIndex
            For nIndex = 1 to Len(sString)
               CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
            Next
      End Function

      'Byte string to string conversion
      Private Function CWideString(bsString)
            Dim nIndex
            CWideString =""
            For nIndex = 1 to LenB(bsString)
               CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1)))
            Next
      End Function
End Class

Class UploadedFile
      Public ContentType
      Public FileName
      Public FileData
      
      Public Property Get FileSize()
            FileSize = LenB(FileData)
      End Property

      Public Sub SaveToDisk(sPath)
            Dim oFS, oFile
            Dim nIndex
      
            If sPath = "" Or FileName = "" Then Exit Sub
            If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
      
            Set oFS = Server.CreateObject("Scripting.FileSystemObject")
            If Not oFS.FolderExists(sPath) Then Exit Sub
            
            Set oFile = oFS.CreateTextFile(sPath & FileName, True)
            
            For nIndex = 1 to LenB(FileData)
                oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
            Next

            oFile.Close
      End Sub
      
      Public Sub SaveToDatabase(ByRef oField)
            If LenB(FileData) = 0 Then Exit Sub
            
            If IsObject(oField) Then
                  oField.AppendChunk FileData
            End If
      End Sub

End Class
%>

How can i fix this?
Avatar of Preece
Preece
Flag of United States of America image

Just a guess, but is the upload.asp file in the same folder as your /flashsystem/sendflash.asp file?  If not, then you'll need to reference it:

<!-- #include file="/somedir/upload.asp" -->

Preece
Avatar of cookiejest
cookiejest

ASKER

yeh its in the same place on the server.
has anybody else got an idea?
Avatar of fritz_the_blank
What does this give you?


<%
<!-- #include file="upload.asp" -->
'Dimension variables
Dim adoCon              'Holds the Database Connection Object
Dim rs   'Holds the recordset for the new record to be added
Dim strSQL               'Holds the SQL query to query the database
Dim Uploader, File
Set Uploader = New FileUploader

' This starts the upload process
Uploader.Upload()

Response.write varType(Uploader)
response.end

FtB
Also, may I see the form tag from the previous page?

FtB
ASKER CERTIFIED SOLUTION
Avatar of kevp75
kevp75
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial