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) ...
| |||||||
|
#1
| ||||
| ||||
| 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
| ||||
| ||||
| 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")
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 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
| ||||
| ||||
| 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
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
__________________ 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
| ||||
| ||||
| 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. |
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| 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 |