Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2003, 09:56 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Uploading and Updating in same page

Hi All,

I could really use some help with my application. I am puting on my website a place where scanned invoices can be accessed. The user can upload an invoice for display but in the same process the database will be updated with the information so that it appears within the page. I have made the code and it does upload the image, however, the same page contains code to update the database and although the page runs correctly and does not report any errors the database does not get updated... I will show you my code.


<%
    Response.Buffer = True

    Dim load
        Set load = new Loader
        load.initialize

    ' File binary data
    Dim fileData, fileName, filePath, filePathComplete, fileSize, fileSizeTranslated, contentType
    Dim countElements, nameInput, pathToFile, filuploadfacteUploaded, strSQL, dbDir
        varDate = Now()
        fileData = load.getFileData("file")
        fileName = LCase(load.getFileName("file"))
        filePath = load.getFilePath("file")
        filePathComplete = load.getFilePathComplete("file")
        fileSize = load.getFileSize("file")
        fileSizeTranslated = load.getFileSizeTranslated("file")
        contentType = load.getContentType("file")
        countElements = load.Count
        nameInput = load.getValue("name")
        pathToFile = Server.mapPath("fac/") & "\" & fileName
        fileUploaded = load.saveToFile ("file", pathToFile)
    Set load = Nothing

set DbConn = Server.CreateObject("ADODB.Connection")
DbConn.Open "DSN=sii"

On Error Resume Next

strSQL = "UPDATE Facture SET" _
       & " [FScan] = '" & fileName & "'," _
       & " [FScanDate] = '" & varDate & "'" _
       & " WHERE FactureNum = '" & nameInput & "';"
DbConn.Execute(strSQL)
%>

At the top of the code you will see an attachment that includes process and prcedures to make the upload possible. This is the attachment:

<%
    Class Loader
        Private dict

        Private Sub Class_Initialize
            Set dict = Server.CreateObject("Scripting.Dictionary")
        End Sub

        Private Sub Class_Terminate
            If IsObject(intDict) Then
                intDict.RemoveAll
                Set intDict = Nothing
            End If
            If IsObject(dict) Then
                dict.RemoveAll
                Set dict = Nothing
            End If
        End Sub

        Public Property Get Count
            Count = dict.Count
        End Property

        Public Sub Initialize
            Dim binData
                binData = Request.BinaryRead(Request.TotalBytes)
                getData binData
        End Sub

        Public Function getFileData(name)
            If dict.Exists(name) Then
                getFileData = dict(name).Item("Value")
                Else
                getFileData = stringToByte("Not Found")
            End If
        End Function

        Public Function getValue(name)
            If dict.Exists(name) Then
                getValue = dict(name).Item("Value")
                Else
                getValue = "Not Found"
            End If
        End Function

        Public Function saveToFile(name, path)
            If dict.Exists(name) Then
                Dim temp
                    temp = dict(name).Item("Value")
                Dim fso
                    Set fso = Server.CreateObject("Scripting.FileSystemObject")
                Dim file
                    Set file = fso.CreateTextFile(path)
                        For tPoint = 1 to LenB(temp)
                            file.Write Chr(AscB(MidB(temp,tPoint,1)))
                        Next
                        file.Close
                    saveToFile = True
                Else
                    saveToFile = False
            End If
        End Function

        Public Function getFileName(name)
            If dict.Exists(name) Then
                Dim temp, tempPos
                    temp = dict(name).Item("FileName")
                    tempPos = 1 + InStrRev(temp, "\")
                    getFileName = Mid(temp, tempPos)
                Else
                getFileName = "Not Found"
            End If
        End Function

        Public Function getFilePath(name)
            If dict.Exists(name) Then
                Dim temp, tempPos
                    temp = dict(name).Item("FileName")
                    tempPos = InStrRev(temp, "\")
                    getFilePath = Mid(temp, 1, tempPos)
                Else
                getFilePath = "Not Found"
            End If
        End Function

        Public Function getFilePathComplete(name)
            If dict.Exists(name) Then
                getFilePathComplete = dict(name).Item("FileName")
                Else
                getFilePathComplete = "Not Found"
            End If
        End Function

        Public Function getFileSize(name)
            If dict.Exists(name) Then
                getFileSize = LenB(dict(name).Item("Value"))
                Else
                getFileSize = "Not Found"
            End If
        End Function

        Public Function getFileSizeTranslated(name)
            If dict.Exists(name) Then
                temp = 1 + LenB(dict(name).Item("Value"))
                    If Len(temp) <= 3 Then
                        getFileSizeTranslated = temp & " bytes"
                        ElseIf Len(temp) > 6 Then
                        temp = FormatNumber(((temp / 1024) / 1000), 2)
                        getFileSizeTranslated = temp & " megabytes"
                        Else
                        temp = FormatNumber((temp / 1024), 2)
                        getFileSizeTranslated = temp & " kilobytes"
                    End If
                Else
                getFileSize = "Not Found"
            End If
        End Function

        Public Function getContentType(name)
            If dict.Exists(name) Then
                getContentType = dict(name).Item("ContentType")
                Else
                getContentType = "Not Found"
            End If
        End Function

    Private Sub getData(rawData)
        Dim separator
            separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)

        Dim lenSeparator
            lenSeparator = LenB(separator)

        Dim currentPos
            currentPos = 1
        Dim inStrByte
            inStrByte = 1
        Dim value, mValue
        Dim tempValue
            tempValue = ""

        While inStrByte > 0
            inStrByte = InStrB(currentPos, rawData, separator)
            mValue = inStrByte - currentPos

            If mValue > 1 Then
                value = MidB(rawData, currentPos, mValue)

                Dim begPos, endPos, midValue, nValue
                Dim intDict
                    Set intDict = Server.CreateObject("Scripting.Dictionary")

                    begPos = 1 + InStrB(1, value, ChrB(34))
                    endPos = InStrB(begPos + 1, value, ChrB(34))
                    nValue = endPos

                Dim nameN
                    nameN = MidB(value, begPos, endPos - begPos)

                Dim nameValue
                    If InStrB(1, value, stringToByte("Content-Type")) > 1 Then

                        begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
                        endPos = InStrB(begPos + 1, value, ChrB(34))

                        midValue = MidB(value, begPos, endPos - begPos)
                            intDict.Add "FileName", trim(byteToString(midValue))

                        begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
                        endPos = InStrB(begPos, value, ChrB(13))

                        midValue = MidB(value, begPos, endPos - begPos)
                            intDict.Add "ContentType", trim(byteToString(midValue))

                        begPos = endPos + 4
                        endPos = LenB(value)

                        nameValue = MidB(value, begPos, endPos - begPos)
                    Else
                        nameValue = trim(byteToString(MidB(value, nValue + 2)))
                    End If

                    intDict.Add "Value", nameValue
                    intDict.Add "Name", nameN

                    dict.Add byteToString(nameN), intDict
            End If

            currentPos = lenSeparator + inStrByte
        Wend
    End Sub

    End Class

    Private Function stringToByte(toConv)
        Dim tempChar
         For i = 1 to Len(toConv)
             tempChar = Mid(toConv, i, 1)
            stringToByte = stringToByte & chrB(AscB(tempChar))
         Next
    End Function

    Private Function byteToString(toConv)
        For i = 1 to LenB(toConv)
            byteToString = byteToString & chr(AscB(MidB(toConv,i,1)))
        Next
    End Function

%>

The previous page collects the relevant data, such as "file" and "name". Those are the names of the 2 fields... name contains the invoice number and file contains the file path...

What am I doing wrong.. is it because I am trying to use binary data to put in the database... I am not sure if that is the case as I used the VB Command "varType" and it told me 8... which is string...

If anyone knows what I am doing wrong.. please help me out.

With many thanks for your time and support,

Paul Jacobs
 
Old June 25th, 2003, 08:41 AM
Authorized User
 
Join Date: Jun 2003
Posts: 48
Thanks: 0
Thanked 0 Times in 0 Posts
Default

check if u get an error if u disable this line: "On Error Resume Next"

maybe this will help u further.

grtz,

Harold
 
Old June 25th, 2003, 10:18 AM
Authorized User
 
Join Date: Jun 2003
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your assistance

This line does not make any difference, when removed the code still runs, and it does not report any errors, but the database is still not updated...

Thanks, any other suggestions?

Paul Jacobs
 
Old June 25th, 2003, 12:26 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Use Response.Write to output the SQL statement to the browser, then use Response.End to stop further processing (temporarily). Post the output of the Write statement to this list. E.g.:

Code:
strSQL = "UPDATE Facture SET" _
& " [FScan] = '" & fileName & "'," _
& " [FScanDate] = '" & varDate & "'" _
& " WHERE FactureNum = '" & nameInput & "';"

Response.Write("SQL is " & strSQL)
Response.End
DbConn.Execute(strSQL)
Maybe there is something wrong in your WHERE clause. For example, nameInput may contain "Not Found" so no records in the database match your WHERE clause.

HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 30th, 2006, 01:07 PM
Authorized User
 
Join Date: Aug 2006
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello...can u tell me how to retrieve the image from other folder?coz i jz can use the script same as u load the image from the image that put inside a folder in the same directory of the file code.

 
Old August 30th, 2006, 07:58 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

what are you trying to do?

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating Session Variab from Master Page gurbaksh ASP.NET 2.0 Professional 0 February 19th, 2008 05:50 PM
Uploading Rebel BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 November 14th, 2007 06:13 AM
Help in uploading sonurijs Pro JSP 3 March 5th, 2005 04:54 PM
Uploading derek Dreamweaver (all versions) 4 March 8th, 2004 04:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.