SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Uploading form

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Uploading form

    hey guys,
    I've got a problem with my upload form, it has the option to upload up to 4 photos, 1 is a must and the rest are optional (so for example a guy can use photo 1 and photo 3 slots etc) and pet infos

    I'm trying to make the uploading form in a way so first it'll check if the uploaded info is a month dog, if it is then it checks if there are less than 3 month dogs in the db, if not then it goes on and checks the images to validate they are really images, after checking image number 1, it needs to check if there were any other images uploaded on the optional slots, if yes then it checks if they are images, and then uploads them.

    If any of the above checks returns false, then there should be a msg appear saying uploading failed, i've trying building the form over and over for about an hour without any success, here is a part of it, without the checks for the extenstions of the optional image slots (FileName2, 3 and 4)
    i just dont know where to put them so if 1 file doesn't match the requirements it'll go straight to the "uploading failed" msg

    Any help is appreciated,
    Code ASP:
    if upload.fields("submit").value = "submit" then
    DB = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=db.mdb;"
    Set Conn = Server.CreateObject("ADODB.Connection")
    Set RS = Server.CreateObject("ADODB.recordset")
    Conn.Open DB
    Ext = Upload.Fields("File1").FileExt
    Select Case Ext
     Case "GIF", "BMP", "PNG", "JPG", "JPEG" ' Checking for the ext of file number 1
      if upload.fields("animalType1").value = "Month Dog" then ' Checks if the uploaded pet info is a month dog
      ssql = "SELECT AnimalType FROM Animals WHERE (animalType= 'Month Dog')"
      RS.Open ssql, Conn, 3, 3
      numbs = 0
      Do While Not CallToPets.EOF
      numbs = numbs + 1
      CallToPets.MoveNext
      Loop
      CallToPets.Close
      if numbs = 3 then
      rep = "its not allowed to have more than 3 month dogs at a time"
      else ' If there are less than 3 month dogs
      else ' If the uploaded info is not a month dog
      ssql = "Animals WHERE FileID = 0"
      RS.Open ssql, Conn, 3, 3
      RS.AddNew
      ' Adding pet infos to the DB
      RS.Update
      RS.MoveLast
      FileID = RS.Fields("ID").Value
      RS.Close
      FileName = Upload.Fields("File1").FileName
      FileName2 = Upload.Fields("File2").FileName
      FileName3 = Upload.Fields("File3").FileName 
      FileName4 = Upload.Fields("File4").FileName
      Set fso = server.CreateObject("Scripting.FileSystemObject")
      Folder = Server.MapPath("photos") & "/Photos/"
      FileName = Upload.UniqueName(folder, FileName)
      Upload("File1").SaveAs Folder & FileName
      Updating = "update Animals set FileName='" & FileName & "' where ID=" & FileID
      Conn.execute Updating
      if Upload.Fields("File2").length > 0 then ' Checks if image number 2 slot was used
      FileName2 = Upload.UniqueName(folder, FileName2)
      Upload("File2").SaveAs Folder & FileName2
      Updating = "update Animals set FileName2='" & FileName2 & "' where ID=" & FileID
      Conn.execute Updating
      end if
      if Upload.Fields("File3").length > 0 then ' Checks if image number 3 slot was used
      FileName3 = Upload.UniqueName(folder, FileName3)
      Upload("File3").SaveAs Folder & FileName3
      Updating = "update Animals set FileName3='" & FileName3 & "' where ID=" & FileID
      Conn.execute Updating
      end if
      if Upload.Fields("File4").length > 0 then ' Checks if image number 4 slot was used
      FileName4 = Upload.UniqueName(folder, FileName4)
      Upload("File4").SaveAs Folder & FileName4
      Updating = "update Animals set FileName4='" & FileName4 & "' where ID=" & FileID
      Conn.execute Updating
      end if
      Conn.Close
      Set RS = Nothing
      Set Conn = Nothing
      Set Upload = Nothing
      Set fso = Nothing
      rep = "The information updated succesfully"
      end if
      end if
     Case Else
      rep = "Uploading failed"
      Conn.Close
      Set RS = Nothing
      Set Conn = Nothing
      Set Upload = Nothing
    End Select
    end if

    There's probably need to be a big change to the whole code in order to make it throw the "uploading failed" msg as soon as 1 of the requirements fails

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    phew, after a few hours of thinking through that thing, i got it solved
    So here is the solution if any1 is intrested

    Code ASP:
    if upload.fields("submit").value = "send" then
    DB = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\sites\Single56\sospets\database\animals.mdb; Persist Security Info=False"
    Set Conn = Server.CreateObject("ADODB.Connection")
    Set RS = Server.CreateObject("ADODB.recordset")
    Conn.Open DB
    FileOK = true
    if upload.fields("animalType1").value = "month dog" then
    Testing1 = "SELECT AnimalType FROM Animals WHERE (animalType= 'month dog')"
    RS.Open Testing1, Conn, 3, 3
    numbs = 0
    Do While Not RS.EOF
    numbs = numbs + 1
    RS.MoveNext
    Loop
    RS.Close
    if numbs = 3 then
    FileOK = False
    else
    FileOK = True
    end if
    end if
    Ext = Upload.Fields("File1").FileExt
     Select Case Ext
    	Case "GIF", "BMP", "PNG", "JPG", "JPEG"
    		FileOK2 = True
    	Case Else
    		FileOK2 = False
     End Select
    FileOK3 = True
    if Upload.Fields("File2").length > 0 then
    Ext = Upload.Fields("File2").FileExt
     Select Case Ext
    	Case "GIF", "BMP", "PNG", "JPG", "JPEG"
    		FileOK3 = True
    	Case Else
    		FileOK3 = False
     End Select
    end if
    FileOK4 = True
    if Upload.Fields("File3").length > 0 then
    Ext = Upload.Fields("File3").FileExt
     Select Case Ext
    	Case "GIF", "BMP", "PNG", "JPG", "JPEG"
    		FileOK4 = True
    	Case Else
    		FileOK4 = False
     End Select
    end if
    FileOK5 = True
    if Upload.Fields("File4").length > 0 then
    Ext = Upload.Fields("File4").FileExt
     Select Case Ext
    	Case "GIF", "BMP", "PNG", "JPG", "JPEG"
    		FileOK5 = True
    	Case Else
    		FileOK5 = False
     End Select
    end if
    if FileOK = true and FileOK2 = true and FileOK3 = true and FileOK4 = true and FileOK5 = true then
    UploadingInfos = "Animals WHERE FileID = 0"
    RS.Open UploadingInfos, Conn, 3, 3
    ' Adding records to the DB
    RS.Update
    RS.MoveLast
    FileID = CallToPets.Fields("ID").Value
    RS.Close
    FileName = Upload.Fields("File1").FileName
    FileName2 = Upload.Fields("File2").FileName
    FileName3 = Upload.Fields("File3").FileName 
    FileName4 = Upload.Fields("File4").FileName
    Set fso = server.CreateObject("Scripting.FileSystemObject")
    Folder = Server.MapPath("photos") & "/PetPhotos/"
    FileName = Upload.UniqueName(folder, FileName)
    Upload("File1").SaveAs Folder & FileName
    Updating = "update Animals set FileName='" & FileName & "' where ID=" & FileID
    Conn.execute Updating
    if Upload.Fields("File2").length > 0 then
    FileName2 = Upload.UniqueName(folder, FileName2)
    Upload("File2").SaveAs Folder & FileName2
    Updating = "update Animals set FileName2='" & FileName2 & "' where ID=" & FileID
    Conn.execute Updating
    end if
    if Upload.Fields("File3").length > 0 then
    FileName3 = Upload.UniqueName(folder, FileName3)
    Upload("File3").SaveAs Folder & FileName3
    Updating = "update Animals set FileName3='" & FileName3 & "' where ID=" & FileID
    Conn.execute Updating
    end if
    if Upload.Fields("File4").length > 0 then
    FileName4 = Upload.UniqueName(folder, FileName4)
    Upload("File4").SaveAs Folder & FileName4
    Updating = "update Animals set FileName4='" & FileName4 & "' where ID=" & FileID
    Conn.execute Updating
    end if
    Conn.Close
    Set RS = Nothing
    Set Conn = Nothing
    Set Upload = Nothing
    Set fso = Nothing
    rep = "Upload successful"
    else
    Conn.Close
    Set RS = Nothing
    Set Conn = Nothing
    Set Upload = Nothing
    if FileOK = False then
    rep = "cant have more than 3 month dogs at a time"
    elseif FileOK2 = False then
    rep = "File 1 is not an image"
    elseif FileOK3 = False then
    rep = "File 2 is not an image"
    elseif FileOK4 = False then
    rep = "File 3 is not an image"
    elseif FileOK5 = False then
    rep = "File 4 is not an image"
    end if
    end if
    end if


Bookmarks

Posting Permissions

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