Avatar of elieazzi
elieazziFlag for United States of America

asked on 

Upload a file in ASP

Hello,

I want know, what is the code i should put it in my page to be able to receive the file in my email. pls advice.

This is the form:
http://www.caf-fca.org/english/order.asp 

This is the code on this page:

         <form name="YourFormName" method="Post" action="orderconf.asp" onSubmit="return checkForm(this);">
.....          
  <TR>
            <TD colSpan=2>Do you have any file to upload: Optional Upload File<br>
      <input type="file" name="opt_file[0]" value="" size="35" /></td>
      </TD></TR>
.....

Pls advice.
And on the form orderconf.asp 
 
I add this line to have the file.
 
<%
DIM strEmail, strName, strComments, objMail
strName = Request.Form("TxtFName")
strComments = Request.Form("TxtTitle")
 
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "info@caf-fca.org"
objMail.Subject = "Reports Survey - Online Transaction " & Request.Form("TxtFName") 
objMail.To = "elie_azzi@caf-fca.org"
objMail.cc = "elie_azzi@caf-fca.org"
objMail.Body = "Email: " & strEmail & vbCrLf & _
"Name: " & strName & vbCrLf & _
"Title: " & vbCrLf & strComments
objMail.BodyFormat=0   
objMail.MailFormat=0
objMail.Importance = 2
 
objMail.body="<html>" & VBCrLF & "<Title></Title>" & VBCrLf & "<Head></Head>" & VBCrLf & "<Body>" & vbCrLf & _ 
"<h3><center><font color=red>Making it work! - Online Order</font></center></h3>" & VBCrLf & _
"<p><strong>Date Submitted:</strong> " & Now() & VBCrLf & VBCrLf & _
"<h3><font color=Blue>Billing Address:</font></h3>" & VBCrLf & _
"<p><strong>Name:</strong> " & Request.Form("salutation") & "  " & Request.Form("TxtFName") & "  " & Request.Form("TxtMName") & "  " & Request.Form("TxtLName")& VBCrLf & VBCrLf & _
"<h4><font color=red>Quantity and Description</font></h4>" & VBCrLf & _
"<p><strong>Title:</strong> " & Request.Form("txtTitle") & VBCrLf & VBCrLf & _
"<p><strong>Department:</strong> " & Request.Form("TxtDepartment") & VBCrLf & VBCrLf & _
"<p><strong>Organization:</strong> " & Request.Form("TxtOrganization") & VBCrLf & VBCrLf & _
"<p><strong>Address:</strong> " & Request.Form("TxtAddress") & VBCrLf & VBCrLf & _
"<p><strong>City:</strong> " & Request.Form("TxtCity") & VBCrLf & VBCrLf & _
"<p><strong>Email:</strong> " & Request.Form("email") & VBCrLf & VBCrLf & _
"<p><strong>Province:</strong> " & Request.Form("Province") & VBCrLf & VBCrLf & _
"<p><strong>File:</strong> " & Request.Form("file") & VBCrLf & VBCrLf & _
"<p><strong>Postal Code:</strong> " & Request.Form("txtPostalCode1") & " - " & Request.Form("txtPostalCode2") & VBCrLf & VBCrLf & _
"<p><strong>Telephone:</strong> " & "(" & Request.Form("phone1") & ") " & Request.Form("phone2") & "-" & Request.Form("phone3") & " Ext. " & Request.Form("phone4") &VBCrLf & VBCrLf & _
"<p><strong>Fax:</strong> " & "(" & Request.Form("fax1") & ") " & Request.Form("fax2") & "-" & Request.Form("fax3") &VBCrLf & VBCrLf & _
"<p><strong>Name of report / resource:</strong> Apprenticeship Labour Market Outcomes in Canada since 2000 " & VBCrLf & VBCrLf & _
"<p><strong>User Category:</strong> " & Request.Form("UserCategory") & VBCrLf & VBCrLf & _
"<p><strong>The purpose for downloading the information:</strong> " & Request.Form("purpose") & VBCrLf & VBCrLf & _
"<p><strong>Any more information and/or to receive our newsletters and other communications:</strong> " & Request.Form("specialreq") & VBCrLf & VBCrLf & _
"<p><strong>Please provide your email address:</strong> " & Request.Form("NewslettersEmail") & VBCrLf & VBCrLf & _
"</body>" & VBCrLf & "</html>"
objMail.Send
Set objMail = nothing
%>

Open in new window

ASP

Avatar of undefined
Last Comment
elieazzi
SOLUTION
Avatar of the_crazed
the_crazed
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of elieazzi
elieazzi
Flag of United States of America image

ASKER


The crazed,

Thank you but i'm not an expert in ASP. would you please give me the code to put it on my form.

thx.
Avatar of the_crazed
the_crazed
Flag of United Kingdom of Great Britain and Northern Ireland image

hi elieazzi,
     that's not really the service offered here (writing code for you) - what we do is help you write the code yourself, and help you through difficulties you might have. If you think about it, that way everyone wins!
     So, as you've nearly got number 3) sorted in your code above, so lets start with 1) and 2).
     have a look at the article here:  
     http://www.asp101.com/articles/jacob/scriptupload.asp

     1) download the sample (fileuploader.zip) and extract it to a folder on your webserver.
     2) customise uploadform.htm to meet your needs (maybe add some fileds or remove the fullname field, remove to saveto choices)
     3) comment out all the stuff in uploadexample.asp relating to Uploader.Form("saveto") and to writing to the database (thats line 34 and 39-56)
     4) add around line 15:
Dim strUploadPath, strFilePath
Dim strEmail, strName, strComments, objMail
strUploadPath = "[folder on your webserver, ending in "\"]"
     5) alter line 37 to:
File.SaveToDisk  strUploadPath
     6) add after line 61:
strFilePath = strUploadPath & File.FileName
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "info@caf-fca.org"
objMail.Subject = "Reports Survey - Online Transaction "
objMail.To = "elie_azzi@caf-fca.org"
objMail.cc = "elie_azzi@caf-fca.org"
objMail.Body = "Test Email"
objMail.BodyFormat=0  
objMail.MailFormat=0
objMail.Importance = 2
objMail.AttachFile(strFilePath)
 
objMail.Send
Set objMail = nothing
   
     7) try it out!

now you should have a working example, and you can start putting the necessary code back into your original form. any problems, post here and I will help you through them.
Avatar of elieazzi
elieazzi
Flag of United States of America image

ASKER

I would like to thank you for giving me the change to participate :).

Here what i did:
http://www.caf-fca.org/english/fileuploader/uploadform.htm 

1. If i don't select a file i'm getting a response: File(s) not uploaded.
2. If I select a file i'm getting a error page.

Please note for you information the foler name on the server is UploadedFiles

D:\Inetpub\www\www.caf-fca.org\english\UploadedFiles

I've attached both code uploadexmple.asp

Again, thank you for your patiente :) and i'm happy i'm learning with your support!!!

' Here is the code for http://www.caf-fca.org/english/fileuploader/uploadform.htm
 
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadexmple.asp">
	<TABLE BORDER=0>
	<tr><td><b>Enter your fullname:</b><br><INPUT TYPE=TEXT SIZE=40 NAME="FULLNAME"></td></tr>
	<tr><td><b>Select a file to upload:</b><br><INPUT TYPE=FILE SIZE=50 NAME="FILE1"></td></tr>
	<tr><td><b>Save To:</b>&nbsp;&nbsp;
		Disk&nbsp;<INPUT TYPE=RADIO NAME="saveto" value="disk" checked>&nbsp;&nbsp;
		Database&nbsp;<INPUT TYPE=RADIO NAME="saveto" value="database">
	</td></tr>
	<tr><td align="center"><INPUT TYPE=SUBMIT VALUE="Upload!"></td></tr>
	</TABLE>
</FORM>
</BODY>
</HTML>
 
 
Then here is the code for: uploadexmple.asp
 
<%@ Language=VBScript %>
<%Option Explicit%>
<!-- #include file="upload.asp" -->
<%
 
'NOTE - YOU MUST HAVE VBSCRIPT v5.0 INSTALLED ON YOUR WEB SERVER
'	   FOR THIS LIBRARY TO FUNCTION CORRECTLY. YOU CAN OBTAIN IT
'	   FREE FROM MICROSOFT WHEN YOU INSTALL INTERNET EXPLORER 5.0
'	   OR LATER.
 
 
' Create the FileUploader
Dim Uploader, File
Set Uploader = New FileUploader
Dim strUploadPath, strFilePath
Dim strEmail, strName, strComments, objMail
strUploadPath = "[UploadedFiles]"
 
' This starts the upload process
Uploader.Upload()
 
'******************************************
' Use [FileUploader object].Form to access 
' additional form variables submitted with
' the file upload(s). (used below)
'******************************************
Response.Write "<b>Thank you for your upload " & Uploader.Form("fullname") & "</b><br>"
 
' Check if any files were uploaded
If Uploader.Files.Count = 0 Then
	Response.Write "File(s) not uploaded."
Else
	' Loop through the uploaded files
	For Each File In Uploader.Files.Items
		
		' Check where the user wants to save the file
	'	If Uploader.Form("saveto") = "disk" Then
	
			' Save the file
			'File.SaveToDisk "E:\UploadedFiles\"
			File.SaveToDisk  strUploadPath
 
	
	'	ElseIf Uploader.Form("saveto") = "database" Then
			
			' Open the table you are saving the file to
	'		Set RS = Server.CreateObject("ADODB.Recordset")
	'		RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2
	'		RS.AddNew ' create a new record
			
	'		RS("filename")    = File.FileName
	'		RS("filesize")	  = File.FileSize
	'		RS("contenttype") = File.ContentType
		
			' Save the file to the database
	'		File.SaveToDatabase RS("filedata")
			
			' Commit the changes and close
	'		RS.Update
	'		RS.Close
	'	End If
	strFilePath = strUploadPath & File.FileName
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "info@caf-fca.org"
objMail.Subject = "Reports Survey - Online Transaction "
objMail.To = "elie_azzi@caf-fca.org"
objMail.cc = "elie_azzi@caf-fca.org"
objMail.Body = "Test Email"
objMail.BodyFormat=0   
objMail.MailFormat=0
objMail.Importance = 2
objMail.AttachFile(strFilePath)
 
objMail.Send
Set objMail = nothing
 
		
		' Output the file details to the browser
		Response.Write "File Uploaded: " & File.FileName & "<br>"
		Response.Write "Size: " & File.FileSize & " bytes<br>"
		Response.Write "Type: " & File.ContentType & "<br><br>"
	Next
End If
 
%>

Open in new window

Avatar of the_crazed
the_crazed
Flag of United Kingdom of Great Britain and Northern Ireland image

hi elieazzi,
    sorry, forgot to say that you need to specify the full file path to the upload destination
    so your line 17 should be:
strUploadPath = "D:\Inetpub\www\www.caf-fca.org\english\UploadedFiles"

Open in new window

Avatar of the_crazed
the_crazed
Flag of United Kingdom of Great Britain and Northern Ireland image

sorry, make that
strUploadPath = "D:\Inetpub\www\www.caf-fca.org\english\UploadedFiles\"

Open in new window

Avatar of elieazzi
elieazzi
Flag of United States of America image

ASKER

Hi There,

I've copied line and line and i'm trobloushooting... It's ben one hour and i'm not able to see why... Crasy ASP, I've implement this form to my page:


http://www.caf-fca.org/english/order.asp 
   
                    Please provide a copy of the article with this report
   
     
            Enter the article name:
                           
           
            Select a file to upload:
             
         

And here is the code for the others page:  http://www.caf-fca.org/english/orderconf.asp


Pls test why is giving me the error... Thanks

' Here is the code. http://www.caf-fca.org/english/order.asp 
....  
 <tr><td colspan="2"><LABEL class=preField id=mi-L for=mi style="width:600px;" for=category>
                    <strong>Please provide a copy of the article with this report</strong></label></td></tr>
    
     <TR>
            <TD><LABEL class=preField id=mi-L for=mi style="width:150px;" for=category>Enter the article name:</label>
              <INPUT TYPE=TEXT SIZE=30 NAME="FULLNAME">              
            </TD>
            <TD><LABEL class=preField id=mi-L for=mi style="width:150px;" for=category>Select a file to upload:</label>
              <INPUT TYPE=FILE SIZE=30 NAME="FILE1"></TD>
          </TR>
......
 
And here is the code for the other page":
 
<script language="JavaScript" type="text/JavaScript">
<!--
 
 
 
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
<link href="../dp12orangew3c.css" rel="stylesheet" type="text/css">
<link href="../style.css" rel="stylesheet" type="text/css">
<script language="javascript">
function Clickheretoprint()
{ 
  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
      disp_setting+="scrollbars=yes,width=665, height=600, left=100, top=25"; 
  var content_vlue = document.getElementById("print_content").innerHTML; 
  
  var docprint=window.open("","",disp_setting); 
   docprint.document.open(); 
   docprint.document.write('<html><head><title>CAF-FCA - Documents and reports</title>'); 
   docprint.document.write('</head><body onLoad="self.print()"><center>');          
   docprint.document.write(content_vlue);          
   docprint.document.write('</center></body></html>'); 
   docprint.document.close(); 
   docprint.focus(); 
}
</script>
</HEAD><BODY BGCOLOR=#ffffff LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<%@ Language=VBScript %>
<%Option Explicit%>
<!-- #include file="upload.asp" -->
<%
 
Dim Uploader, File
Set Uploader = New FileUploader
Dim strUploadPath, strFilePath
DIM strEmail, strName, strComments, objMail
strUploadPath = "D:\Inetpub\www\www.caf-fca.org\english\UploadedFiles\"
 
' This starts the upload process
Uploader.Upload()
 
Response.Write "<b>Thank you for your upload " & Uploader.Form("fullname") & "</b><br>"
 
' Check if any files were uploaded
If Uploader.Files.Count = 0 Then
	Response.Write "File(s) not uploaded."
Else
	' Loop through the uploaded files
	For Each File In Uploader.Files.Items
		
		' Check where the user wants to save the file
	'	If Uploader.Form("saveto") = "disk" Then
	
			' Save the file
			'File.SaveToDisk "E:\UploadedFiles\"
			File.SaveToDisk  strUploadPath
 
	
	'	ElseIf Uploader.Form("saveto") = "database" Then
			
			' Open the table you are saving the file to
	'		Set RS = Server.CreateObject("ADODB.Recordset")
	'		RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2
	'		RS.AddNew ' create a new record
			
	'		RS("filename")    = File.FileName
	'		RS("filesize")	  = File.FileSize
	'		RS("contenttype") = File.ContentType
		
			' Save the file to the database
	'		File.SaveToDatabase RS("filedata")
			
			' Commit the changes and close
	'		RS.Update
	'		RS.Close
	'	End If
	strFilePath = strUploadPath & File.FileName
 
 
strName = Request.Form("TxtFName")
strComments = Request.Form("TxtTitle")
strFilePath = strUploadPath & File.FileName
 
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "info@caf-fca.org"
objMail.Subject = "Reports Survey - Online Transaction " & Request.Form("TxtFName") 
objMail.To = "elie_azzi@caf-fca.org"
objMail.cc = "elie_azzi@caf-fca.org"
objMail.Body = "Email: " & strEmail & vbCrLf & _
"Name: " & strName & vbCrLf & _
"Title: " & vbCrLf & strComments
objMail.BodyFormat=0   
objMail.MailFormat=0
objMail.Importance = 2
objMail.AttachFile(strFilePath)
 
objMail.Send
Set objMail = nothing
 
objMail.body="<html>" & VBCrLF & "<Title></Title>" & VBCrLf & "<Head></Head>" & VBCrLf & "<Body>" & vbCrLf & _ 
"<h3><center><font color=red>Making it work! - Online Order</font></center></h3>" & VBCrLf & _
"<p><strong>Date Submitted:</strong> " & Now() & VBCrLf & VBCrLf & _
"<h3><font color=Blue>Billing Address:</font></h3>" & VBCrLf & _
"<p><strong>Name:</strong> " & Request.Form("salutation") & "  " & Request.Form("TxtFName") & "  " & Request.Form("TxtMName") & "  " & Request.Form("TxtLName")& VBCrLf & VBCrLf & _
"<h4><font color=red>Quantity and Description</font></h4>" & VBCrLf & _
"<p><strong>Title:</strong> " & Request.Form("txtTitle") & VBCrLf & VBCrLf & _
"<p><strong>Department:</strong> " & Request.Form("TxtDepartment") & VBCrLf & VBCrLf & _
"<p><strong>Organization:</strong> " & Request.Form("TxtOrganization") & VBCrLf & VBCrLf & _
"<p><strong>Address:</strong> " & Request.Form("TxtAddress") & VBCrLf & VBCrLf & _
"<p><strong>City:</strong> " & Request.Form("TxtCity") & VBCrLf & VBCrLf & _
"<p><strong>Email:</strong> " & Request.Form("email") & VBCrLf & VBCrLf & _
"<p><strong>Province:</strong> " & Request.Form("Province") & VBCrLf & VBCrLf & _
"<p><strong>File:</strong> " & Request.Form("file") & VBCrLf & VBCrLf & _
"<p><strong>Postal Code:</strong> " & Request.Form("txtPostalCode1") & " - " & Request.Form("txtPostalCode2") & VBCrLf & VBCrLf & _
"<p><strong>Telephone:</strong> " & "(" & Request.Form("phone1") & ") " & Request.Form("phone2") & "-" & Request.Form("phone3") & " Ext. " & Request.Form("phone4") &VBCrLf & VBCrLf & _
"<p><strong>Fax:</strong> " & "(" & Request.Form("fax1") & ") " & Request.Form("fax2") & "-" & Request.Form("fax3") &VBCrLf & VBCrLf & _
"<p><strong>Name of report / resource:</strong> Apprenticeship Labour Market Outcomes in Canada since 2000 " & VBCrLf & VBCrLf & _
"<p><strong>User Category:</strong> " & Request.Form("UserCategory") & VBCrLf & VBCrLf & _
"<p><strong>The purpose for downloading the information:</strong> " & Request.Form("purpose") & VBCrLf & VBCrLf & _
"<p><strong>Any more information and/or to receive our newsletters and other communications:</strong> " & Request.Form("specialreq") & VBCrLf & VBCrLf & _
"<p><strong>Please provide your email address:</strong> " & Request.Form("NewslettersEmail") & VBCrLf & VBCrLf & _
"</body>" & VBCrLf & "</html>"
objMail.Send
Set objMail = nothing
 
Next
End If
 
%>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of the_crazed
the_crazed
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of elieazzi
elieazzi
Flag of United States of America image

ASKER

Thank you very much!
ASP
ASP

Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.

82K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo