Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "Free ASP Upload Question" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). Visit the ASP Development forum for help with ASP/VBScript and ASP/JScript applications.


Closed Thread
 
LinkBack Thread Tools Display Modes
  #1  
Old July 16th, 2008, 02:45 PM
Rebelle's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 295
Thanks: 54
Thanked 1 Time in 1 Post
Rep Power: 1
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
Sponsored Links
  #2  
Old July 17th, 2008, 01:47 AM
richyrich's Avatar
Super Moderator
 
Join Date: Mar 2008
Location: Somewhere only we know...
Posts: 460
Thanks: 31
Thanked 43 Times in 43 Posts
Blog Entries: 1
Rep Power: 2
richyrich will become famous soon enoughrichyrich will become famous soon enough

Awards Showcase
JavaScript Classic ASP 
Total Awards: 2

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: 160
Thanks: 12
Thanked 29 Times in 27 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

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:
Quality: The race for quality has no finish line- so technically, it's more like a death march.

Questions to Ponder:
What do you do when you see an endangered animal eating an endangered plant?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright © 2008 sbenj69
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: 160
Thanks: 12
Thanked 29 Times in 27 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

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

Forum Jump

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 09:34 AM.



Content Relevant URLs by vBSEO 3.2.0