Closed Thread
Results 1 to 4 of 4

Thread: Free ASP Upload Question

  1. #1
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Free ASP Upload Question

    All,

    Ok, I've uploaded this on a development server to try to figure out how it works and such....

    1) I noticed I can upload the same file twice.....It looks it just gets overwritten each time. How / where can I begin to stop this? Because I don't want it to overwrite if user1 submits file name "pic1.jpg" and user2 submits file name "pic1.jpg". tried to add this but not working Upload.OverwriteFiles = False.

    Reason: I'm going to have a form where I want to allow 2 files (max) to be uploaded but at the same time I will take all other fields in the form and insert them into a database and I would like to somehow link the files attached to the inserted record.

    So later after I've submitted a form (fields and 2 files) then I can search and see that form data with those pictures.

    Here is what I try but get error below after code(line in red):
    Code:
    function SaveFiles
        Dim Upload, fileName, fileSize, ks, i, fileKey
    
        Set Upload = New FreeASPUpload
        Upload.OverwriteFiles(uploadsDirVar) = False    
    
    Upload.Save(uploadsDirVar)
    
    Code:
    Microsoft VBScript runtime error '800a01b6' 
    
    Object doesn't support this property or method: 'Upload.OverwriteFiles'
    
    Last edited by Rebelle; July 16th, 2008 at 10:37 PM. Reason: added code

  2. #2
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    1,724
    Blog Entries
    10
    Rep Power
    11

    Although I don't use FreeASPUpload, I use the following logic to check if the file already exists.

    In my case I can check the filename property before calling the save method. I'm not sure you can do that with this script, so you may have to upload to a temp folder first.

    Get the filename(s) using something like:-
    Code:
    objUpload.UploadedFiles("name_of_form_element").FileName
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    
    Then use FSO to check if the file exists in your "real" upload folder.
    Code:
    If FSO.FileExists(server.mappath("path_to_your_final_upload_folder")) = True then
    'File already exists
    else
    'File doesnot exist
    end if
    Set FSO = Nothing
    
    If you can't get the filenames without calling the Save method first, then if the file doesn't exist, you can then use the same FSO object to move the file to the correct folder and delete it from the temp folder.

    If it does exist then you can write a message to the screen.

    Hope that helps.

  3. #3
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    There's a section of the freeaspuload code that looks like this:
    Code:
    Public Sub Save(path)
        Dim streamFile, fileItem
    
        if Right(path, 1) <> "\" then path = path & "\"
    
        if not uploadedYet then Upload
    
        For Each fileItem In UploadedFiles.Items
          Set streamFile = Server.CreateObject("ADODB.Stream")
          streamFile.Type = 1
          streamFile.Open
          StreamRequest.Position=fileItem.Start
          StreamRequest.CopyTo streamFile, fileItem.Length
          streamFile.SaveToFile path & fileItem.FileName, 2
          streamFile.close
          Set streamFile = Nothing
          fileItem.Path = path & fileItem.FileName
         Next
      End Sub
    
    try changing that section to this:
    Code:
    Public Sub Save(path)
        Dim streamFile, fileItem
        if Right(path, 1) <> "\" then path = path & "\"
        if not uploadedYet then Upload
        Dim newFileName, fs ' declare new empty variables
        set fs=Server.CreateObject("Scripting.FileSystemObject") ' set 1 variable to be the file system object (which has the power to manipulate files)
        For Each fileItem In UploadedFiles.Items ' loop through each file that's been uploaded when the page was submitted
          newFileName = fileItem.FileName ' assign the file name to check to be this file's name
          if fs.FileExists(path & newFileName) then ' use the file system object to check the current file's existence
             response.write("<span class=""color:#ff0000;"">" & newFileName & " exists and could not be saved; please rename and try again.</span>") ' the file exists so through an error
          else
             Set streamFile = Server.CreateObject("ADODB.Stream") ' do the normal save stuff that was there before
             streamFile.Type = 1
             streamFile.Open
             StreamRequest.Position=fileItem.Start
             StreamRequest.CopyTo streamFile, fileItem.Length
             streamFile.SaveToFile path & newFileName, 2
             streamFile.close
             Set streamFile = Nothing
             fileItem.Path = path & newFileName
          end if
        Next
    End Sub
    
    let me know how it works for you.
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  4. #4
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    glad it worked for you ... although it wasn't my code, i found it on another site awhile ago and it's part of my code bank.
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

Closed Thread

Similar Threads

  1. asp.net 2.0 begineers question
    By todd2006 in forum .Net Development
    Replies: 2
    Last Post: July 14th, 2008, 09:29 AM
  2. Excel question
    By Rebelle in forum Microsoft Office
    Replies: 11
    Last Post: May 27th, 2008, 07:22 PM
  3. C# database question
    By peebman2000 in forum .Net Development
    Replies: 19
    Last Post: April 21st, 2008, 03:23 PM

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

SEO by vBSEO