Forum Moderators: open

Message Too Old, No Replies

Attaching a file to a form with ASP?

seems simple...but can't figure it out!

         

rasta richie

9:30 pm on Dec 2, 2002 (gmt 0)

10+ Year Member



Trying to create a form that people can attach a document or image file to. Form results to be e-mailed. Can't seem to get the "file field" in Dreamweaver to work correctly. I may not even have the correct asp code, but any help or code tips are appreciated.

RS

tedster

10:04 pm on Dec 2, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome [webmasterworld.com] to WebmasterWorld, rasta_richie

I moved your question over here to the Microsoft (.NET and ASP) forum -- it's a better place for the conversation and I am pretty much a total hack with ASP anyway.

I'm sure someone will come along soon with some help.

defanjos

2:25 am on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Have you looked into ASPmail?
Your web hosting company might have it available already. I think it will do what you need.

Do a search -- on Google of course :) -- for it, so you can learn more about it.

BlobFisk

10:23 am on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it the form code or the attaching the file to the email code?

The form code is: <input type="file" name="file">. You will also need to andd ENCTYPE="multipart/form-data" to your <form> field. Because of the ENCTYPE attribute, you will have to change from the standard Response.Form to Upload.Form. Upload.Form acts in the exact same way as Response.Form when it comes to taking in variables from the form.

Attaching the file to the email depends on which way you are creating the email in ASP, using CDONTS:

objMail.AttachFile Server.MapPath("/files/file.txt")

The thing is that you need to process the form attached file before you can hope of sending it as an attachment in your ASP mail. It needs to come from the users machine to your server (via the form processing page) and then from your server as the email attachment.

<added>Enctype description</added>

aspdaddy

11:49 am on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thats true, you generally need two components to do this. Though, you can do the upload part with a script - check out ScriptUtils pure asp upload.

BlobFisk

12:05 pm on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



aspdaddy,

Does this use an ISAPI extension based upload rather than an ASP executed upload?

aspdaddy

12:10 pm on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bob - Sorry I dont understand your question.

Its a vbscript class that uses the BinaryRead method of the request object.

It has worked for me on various servers where I have no option to make any mods to server settings etc.

Does this answer the question..

BlobFisk

12:21 pm on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was reading this article [programmersheaven.com] last week on this theme. It talks about the advantages of using ISAPI extentions over ASP scripts, notably the time it takes to process the request.

I'm not at all well versed in ISAPI, but the article talks about using the associated http packet which describes the mime-type of the server request. If I read it correctly, you can use an extention to parse the request. I'm still getting to grips with the content of the article, but it seems to highlight a superior performance enhancement.

rasta richie

12:41 pm on Dec 3, 2002 (gmt 0)

10+ Year Member



Thank you all for helping me with this. Since I am very new to programming...just learning...I am slowly sorting through your comments.

The following is the code I am using in my "mail.asp" file. I am having trouble figuring out where to put "Upload.Form" and "objMail..." as mentioned by BlobFisk.

<%@ Language=VBScript %>
<%
Dim MyMail
Dim MyField
for each MyField in Request.Form
if (MyField <> "To") and (MyField <> "From") and (MyField <> "Subject") and (MyField <> "Redirect") and (MyField <> "Submit") then
myBody = myBody + MyField + ":" + Request.Form(MyField) + Chr(13)
end if
next

Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.To = Request("To")
MyMail.Subject = Request("Subject")
MyMail.From = Request("From")
MyMail.Body = myBody
MyMail.Send
Set myMail = Nothing
Response.Redirect Request("Redirect")
%>

All other code tips from Blob were already utilized in the form code. So I think my problems are coming from the email code (mail.asp). Any further advice?

aspdaddy

12:41 pm on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I agree, but in most cases you will need to manipulate IIS settings for it to work. Sometimes this isnt an option.

RR - First thing to do is ask the server people what they have installed for uploads e.g ASPUpload, XUpload..

BlobFisk

12:53 pm on Dec 3, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



aspodaddy: Very true - in fact, unless you are running your own server this is rarely an option!

rasta_richie:

You need to split the problem into two parts.

(1) Retrieving the file and saving it to your server.

(2) Attaching the file to your email.

As aspdaddy said, it's vital to find out if your hosting service allows file uploads (many have issues with it in terms of bandwidth useage and opening themselves up to malicious files).

In your asp page you will need to take in all the variables from your form, including your file. You will then need to save the file to you server.

Once this is done, you can then begin formatting your mail and attaching the above saved file. Since you know the filename and the location where it was saved, this should be straightforward enough.

HTH

rasta richie

1:00 pm on Dec 3, 2002 (gmt 0)

10+ Year Member



Thanks...I'll check with the ISP.