DeveloperBarn Forums

DeveloperBarn

Programming & IT forum

Free ASP Upload Question

This is a discussion on Free ASP Upload Question within the ASP Development forums, part of the Programming & Scripting category; All, Ok, I've uploaded this on a development server to try to figure out how it works and such.... 1) ...

Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

  #1  
Old July 16th, 2008, 02:45 PM
Rebelle's Avatar
Barn Enthusiast

 
Join Date: Mar 2008
Posts: 496
Thanks: 100
Thanked 3 Times in 3 Posts
Rep Power: 2
Rebelle is on a distinguished road
Question 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  
Old July 17th, 2008, 01:47 AM
richyrich's Avatar
Administrator


 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 876
Thanks: 46
Thanked 76 Times in 75 Posts
Blog Entries: 2
Rep Power: 5
richyrich is just really nicerichyrich is just really nicerichyrich is just really nicerichyrich is just really nice
Default

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.
The Following 2 Users Say Thank You to richyrich For This Useful Post:
BLaaaaaaaaaarche (July 31st, 2008)
  #3  
Old July 17th, 2008, 08:57 AM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 315
Thanks: 16
Thanked 69 Times in 60 Posts
Rep Power: 5
mehere is a jewel in the roughmehere is a jewel in the roughmehere is a jewel in the roughmehere is a jewel in the rough
Default

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.

Comments on this post
Rebelle agrees: This works great! Thanks for the help and thank you for putting in the notes.
__________________
Quote of the Month:
Possibilities: With focus, dedication and steroids, men can achieve impossible dreams. Like breaking a world record. Or growing their own breasts.

Questions to Ponder:
Have you ever imagined a world with no hypothetical situations?

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.
The Following User Says Thank You to mehere For This Useful Post:
Rebelle (July 17th, 2008)
  #4  
Old July 17th, 2008, 12:05 PM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 315
Thanks: 16
Thanked 69 Times in 60 Posts
Rep Power: 5
mehere is a jewel in the roughmehere is a jewel in the roughmehere is a jewel in the roughmehere is a jewel in the rough
Default

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.
Closed Thread

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

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


All times are GMT -4. The time now is 08:22 PM.


Copyright ©2008-2009, DeveloperBarn

Content Relevant URLs by vBSEO 3.3.0