Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Upload Form error... Object required.

    Hello guys,

    I'm new to this forum and in need of some advice...

    I have taught myself ASP and CSS etc, but every now and then, I come up with a challenge. Unfortunately, this challenge I cannot resolve and am now crying for help! First time in 5 years!

    I have used a form with method="post" enctype="multipart/form-data. <input=file and name=file1> and am trying to save the data to a database.

    I have 10x input=file's on my form. If I upload 10 files... no problem, no errors and saves successfully to database. Brilliant! that's what I want.

    THE PROBLEM
    If I want to give the user the option to upload as many as they wish (up to 10), and he/she doesn't use all 10x input=files then an error occurs as no information was inputted in those unused input=files.

    THE ERROR MESSAGE
    "Microsoft VBScript runtime error '800a01a8' Object required: 'Files(...)'"

    CODING IN UPLOAD FILE 1:
    <form action="uploadfile.asp?username=<%=session("username")%>" method="post" enctype="multipart/form-data">
    <br>
    <br>
    <input type="file" name="file1" />
    <br>
    <input type="file" name="file2" />
    <br>
    <input type="file" name="file3" />
    <br>
    <input type="file" name="file4" />
    <br>
    <input type="file" name="file5" />
    <br>
    <input type="file" name="file6" />
    <br>
    <input type="file" name="file7" />
    <br>
    <input type="file" name="file8" />
    <br>
    <input type="file" name="file9" />
    <br>
    <input type="file" name="file10" />
    <br>
    <br>
    <br>
    <input type="submit" value="Upload" name="submit">
    </form>

    CODING IN UPOAD FILE 2

    Dim Conn, strSQL, objExec
    Set Conn = Server.Createobject("ADODB.Connection")
    Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("/DATABASENAME.mdb"),"" , ""

    strSQL = "UPDATE properties set " & vbcrlf
    strSQL = strSQL & "interior_photo1='" & Uploader.files("file1").filename & "', " & vbcrlf
    strSQL = strSQL & "interior_photo2='" & Uploader.files("file2").filename & "' " & vbcrlf
    strSQL = strSQL & "WHERE ID= 232"

    Set objExec = Conn.Execute(strSQL)

    THE PLEA FOR HELP
    Help guys! I have tried inputting a hidden file on my form that copies the file name (using javascript) and then using a request.form but not luck.

    I have tried using If Uploader.files("file2").filename <> "" then else end if but it only brings the same object error to that line.

    I have found this... http://support.persits.com/show.asp?code=PS01032620 but its not helping my case.

    Remember, guys, I've taught myself all this so if it is really something obvious.. and I cannot see if... I can only apologise but be very grateful for your help!

    I think what I need is something to tell the web page that if the input is empty... to ignore it.
    Last edited by revilomedia; 12-07-2011 at 12:00 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    So you are using the Persits file uploader?

    Hmmm...I use it all the time without difficulty.

    But I admit that I usually use code such as
    Code:
    For Each f In Uploader.Files
        ...
    Next
    Maybe you need to use some property other than Filename in the test?

    Have you looked here:
    http://www.aspupload.com/object_file.html
    Maybe you could check the uploaded file's SIZE attribute and do nothing if it is null or zero???

    If you can't get something to work, post again and I'll go play with it on my system.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    In any case, this would never work:
    Code:
    hidden file on my form that copies the file name (using javascript) and then using a request.form ...
    You can *NEVER* mix REQUEST.FORM and UPLOADER. Once you use Request.Form, you can no longer use Uploader.[anything]. Once you have used Uploader.[anything] you can no longer use Request.Form. One or the other; never mix them.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    By the way, it's irrelevant to this post, but it's way way past time that you stopped using the Microsoft.Access driver for hitting ".mdb" databases. Move to the JET OLEDB driver and get much more reliable database handling.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    Oh, DOH on both of us!

    If the message is that there is no such object as Files("file1") then the answer is obvious.

    Persits simply does NOT create a FILE object for any file that isn't uploaded!

    So:

    Code:
    For fnum = 1 To 10
        Set fileobj = Uploader.Files(fnum)
        If NOT (fileobj IS NOTHING) Then
             fname = fileobj.Filename
             ... process this one ...
        End If
    Next
    Or something along those lines. You just have to look for the given FILE object being NOTHING.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    And of course you should also be able to do
    Code:
    If NOT( Uploader.Files("file1") IS NOTHING ) Then
        ...
    End If
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hello "old Pedant"

    Thank you for your help but unfortunately its not worked. Still bouces back saying no object for Uploader.Files("file1").

    All I'm trying to do is have multiple uploads for interior photos on a property website. As its done through the admin panel, I just don't want the user to keep uploading ALL the files. There must be a way I can upload them individually.

  • #8
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This may help... This works but obviously only saves ONE upload to the database. As soon as I input another, it rejects again...

    ' Check if any files were uploaded
    If Uploader.Files.Count = 0 Then
    strMessage = "No file entered."
    Else
    ' Loop through the uploaded files
    For Each File In Uploader.Files.Items

    bolUpload = false

    'Response.Write lngMaxSize
    'Response.End

    if lngFileSize = 0 then
    bolUpload = true
    else
    if File.FileSize > lngFileSize then
    bolUpload = false
    strMessage = "File too large"
    else
    bolUpload = true
    end if
    end if

    if bolUpload = true then
    'Check to see if file extensions are excluded
    If strExcludes <> "" Then
    If ValidFileExtension(File.FileName, strExcludes) Then
    strMessage = "It is not allowed to upload a file containing a [." & GetFileExtension(File.FileName) & "] extension"
    bolUpload = false
    End If
    End If
    'Check to see if file extensions are included
    If strIncludes <> "" Then
    If InValidFileExtension(File.FileName, strIncludes) Then
    strMessage = "It is not allowed to upload a file containing a [." & GetFileExtension(File.FileName) & "] extension"
    bolUpload = false
    End If
    End If
    end if
    if bolUpload = true then
    File.SaveToDisk strFolder ' Save the file
    strMessage = "File Uploaded: " & File.filename

    Dim fs
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    Dim Conn, strSQL, objExec
    Set Conn = Server.Createobject("ADODB.Connection")
    Conn.Open "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("/DATABASE.mdb"),"" , ""
    strSQL = "UPDATE properties set " & vbcrlf

    strSQL = strSQL & "interior_photo1='" & file.filename & "' " & vbcrlf

    strSQL = strSQL & "WHERE ID= 232"
    Set objExec = Conn.Execute(strSQL)
    set fs=nothing

    end if

    Next

    '
    Dim name

    name = Uploader.Form("txtName") 'Used to extract fields in the form
    ' Response.Write "filename : " & name & "<br>"
    'Response.Write "file extension : " & strFileExtension & "<br>"
    'Response.Write strFileExtensions & "<br>"
    'Response.End





    End If
    Last edited by revilomedia; 12-08-2011 at 07:04 PM.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,603
    Thanks
    80
    Thanked 4,500 Times in 4,464 Posts
    You are doing something wrong.

    I used this <form> (essentially identical to yours):
    Code:
    <html>
    <body>
    <form action="uploadfile.asp" method="post" enctype="multipart/form-data">
    <br>
    <br>
    <input type="file" name="file1" />
    <br>
    <input type="file" name="file2" />
    <br>
    <input type="file" name="file3" />
    <br>
    <input type="submit">
    </form>
    </body>
    </html>
    And this is the code for "uploadfile.asp":
    Code:
    <HTML>
    <BODY>
    We got here<hr>
    <%
    Response.Flush
    Set Upload = Server.CreateObject("Persits.Upload")
    Count = Upload.Save
    
    Response.Write Count & " file(s) uploaded<hr/>"
    
    For f = 1 To 3
        Set upfile = Upload.Files("file" & f)
        If upfile IS NOTHING Then
            Response.Write "File" & f & " was *NOT* uploaded<br/>"
        Else
            Response.Write "File" & f & " *WAS* uploaded, file name " & upfile.Filename & "<br/>"
        End If
    Next
    %>
    </BODY>
    </HTML>
    And you can try it yourself at http://www.PlopOn.com/upload.html

    On the HTML page specify any number of files to upload, from 0 to 3, and hit the submit button. The ASP page correctly reports which ones were present in the <form> and, for the ones present, shows their filename.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    revilomedia (12-08-2011)

  • #10
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    IT WORKS!!!

    Many many thanks!!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •