Uploading more than one file in a form (ASP)

Soldato
Joined
18 Oct 2002
Posts
9,044
Location
London
I found a free uploader class (Pure ASP upload) which I'm using very well to upload a file from a form.
Trouble is, I now want two <input type="file" on my form...

This is the bit that saves the files, and records the file name (for viewing purposes)

Code:
For Each File In Uploader.Files.Items
	File.SaveToDisk Server.MapPath("/images/cards/thumbs/")
	cn.execute("UPDATE card SET NewsThumb='"&DoSQL(File.FileName)&"' WHERE card="&cardid)
Next

I'm at a complete loss as to how to set this up for two seperate files.
Obviously I can't use this loop, as it will save update the same value twice. I need a way of finding which file input is being processed.

I thought, easy! Just check to see the name of the file element:

<input type="file" name="file1" />
<input type="file" name="file2" />

If Uploader.Files.Count > 0 Then
response.write "name: " & uploader.form("file1")
End If

However this just outputs "name:"

Does anyone have any ideas? :confused: I can't see how I can find out which file input the user has used.

Thank you for any help! A toughy methinks..
 
Good call, and thanks for the tip. However I get this error:

Object required: 'Uploader.Files(...)'

On the first line of that statement:
Response.Write "File Name:" & Uploader.Files("file1").FileName

Very frustrating. Even that example on the site isn't included in the example file, perhaps it doesn't actually work?
 
Ok thanks for confirming it works :)


Skip to the next post to save your brain energy :)









I looked again, and it seems if you call input name="something" it doesn't work.
Has to be name="file1" etc. Oh well!

This bit is now fine:
Code:
Response.Write "File Name:" & Uploader.Files("file1").FileName
Response.Write "File Name:" & Uploader.Files("file2").FileName
Returns exactly as you'd expect.


However, I'm stuck in that I need to process each of the files seperately.
Code:
'file1 needs to be saved here
File.SaveToDisk Server.MapPath("/images/ecards/thumbs/")

'file2 needs to be saved here
File.SaveToDisk Server.MapPath("/images/ecards/main/")

If I use the loop given:

Code:
For Each File In Uploader.Files.Items
         'something
Next

I won't be able to find out which file is being processed. How can I process each file - depending on if the user has decided to upload one or the other or both?


I thought at first I could do sometihng like:

Uploader.Files("file1").FileName <> "" Then
'upload file1
End If

But if i use:
File.SaveToDisk Server.MapPath("/images/ecards/main/")
this fails because I'm not in that loop...

I hope that makes sense, and thank you for your help!
:o Driving me crazy this is!
 
Last edited:
Ok well I found a really ugly way of doing it, which seems to work for
file1
file2
file1+file2
So that's good enough for me!


Code:
If isObject(Uploader.Files("file1")) Then
	For Each File In Uploader.Files.Items
		response.write"file1: "& Uploader.Files("file1").FileName
		Exit For
	Next
End If
		
		
If isObject(Uploader.Files("file2")) Then
	For Each File In Uploader.Files.Items
		response.write"file2: "& Uploader.Files("file2").FileName
		Exit For
	Next
End If

Isn't it lovely?..

Thanks for your help though! :)
 
Ok Ok Ok. This is why you shouldn't code at night?

Code:
If isObject(Uploader.Files("file1")) Then
	Uploader.Files("file1").SaveToDisk Server.MapPath("/images/special/")
End If

If isObject(Uploader.Files("file2")) Then
	Uploader.Files("file2").SaveToDisk Server.MapPath("/images/veryspecial/")
End If


I'm gonna stop embarassing myself now..
Thanks again!
 
Back
Top Bottom