Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serverfile names of uploaded files

Status
Not open for further replies.

Dynamo3209

Programmer
Jan 2, 2003
57
0
0
US
Hi,
I have a routine to upload upto three files to the server and then email these files the code I am using for uploading the files is
Code:
<cfset filename = "">
<cfloop index="i" from="1" to="3" step="1">
<cfif Len(Trim(form["file" & i]))>
<cffile action="UPLOAD" 
        destination="/[URL unfurl="true"]www/htdocs/abc/report_files/"[/URL] 
	nameconflict="MakeUnique" 
	filefield="file#i#">
<cfset filename = ListAppend(filename, cffile.serverFile)>

</cfif>
</cfloop>

now I have to email these files as attachements for which I am suing the following code
Code:
<cfmail to="abc@yahoo.com"
	from="a@c.com" 
	bcc="b@c.com"
	subject="Results - #FORM.SkipName#, #FORM.AcctNum#, #FORM.SSN1#-#FORM.SSN2#-#FORM.SSN3#"
	spoolenable="false"
	type="HTML"
	Server="mailcf.c.net"
	Port = "25"> 
<cfif isDefined ("FORM.File1")>
  <cfmailparam file= "#FORM.File1#">
  </cfif>
  <cfif isDefined ("FORM.File2")>
  <cfmailparam file= "#FORM.File2#">
  </cfif>
  <cfif isDefined ("FORM.File3")>
  <cfmailparam file= "#FORM.File3#">
  </cfif>

The mail is being sent properly however the files are also being attached however the file names are the ones generated by coldfusion while uploading the files (neotmp30448.tmp) how do I get the proper filenames.
I have tried using #serverfilename#.#serverfileext#, but that doesn't seem to work or I am not using it properly.
Appreciate any help in this regard.

Thanks,
Dynamo
 
try something along these lines

Code:
<cfset filename = "">
[b]<cfset aFiles = arrayNew(1)>[/b]
<cfloop index="i" from="1" to="3" step="1">
<cfif Len(Trim(form["file" & i]))>
<cffile action="UPLOAD" 
        destination="/[URL unfurl="true"]www/htdocs/abc/report_files/"[/URL] 
    nameconflict="MakeUnique" 
    filefield="file#i#">
<cfset filename = ListAppend(filename, cffile.serverFile)>
[b]<cfset aFiles[i] = destination&cffile.serverFile>[/b]
</cfif>
</cfloop>


Code:
<cfmail to="abc@yahoo.com"
    from="a@c.com" 
    bcc="b@c.com"
    subject="Results - #FORM.SkipName#, #FORM.AcctNum#, #FORM.SSN1#-#FORM.SSN2#-#FORM.SSN3#"
    spoolenable="false"
    type="HTML"
    Server="mailcf.c.net"
    Port = "25"> 
<cfif isDefined ("FORM.File1")>
  <cfmailparam file= "#[b]aFiles[1][/b]#">
  </cfif>
  <cfif isDefined ("FORM.File2")>
  <cfmailparam file= "#[b]aFiles[2][/b]#">
  </cfif>
  <cfif isDefined ("FORM.File3")>
  <cfmailparam file= "#[b]aFiles[3][/b]#">
  </cfif>


Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Hi bombboy,
Thanks it worked though instead of
Code:
<cfset aFiles[i] = destination&cffile.serverFile>
used
Code:
<cfset aFiles[i] = cffile.serverFile>
as was getting undefined destination error
and specified the directory while attaching the files in cfmail tag.

Thanks
Dynamo
 
glad it worked. thanks for posting the correction.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top