CFMAIL Attachments Not Named Correctly and Have No File Extension

CFMAIL with attachments was changing the file name and dropping the file extension of the attachments. Email recipients were receiving attachments with no file extension of the same name but with a number appended.

For example, the form had 3 file input fields. The resultant emailed attachments were named, "uploads1", "uploads2", and "uploads3".

The directory intended to store my uploaded files was set:

view plain print about
1<cfset AttachmentDirectory = "uploads" />

The files were stored with CFFILE

view plain print about
1<cfif structKeyExists(form, "ad")>
2    <cfif structKeyExists(form, "FileOne") and form.FileOne is not "">
3        <cffile action="upload" filefield="form.FileOne" destination="#AttachmentDirectory#" nameconflict="makeunique">
4        <cfset FileOneName = CFFILE.ServerFile>    
5        <cfset FileOne = CFFILE.ServerDirectory & "\" & CFFILE.ServerFile>    
6    </cfif>
7    <cfif structKeyExists(form, "FileTwo") and form.FileTwo is not "">
8        <cffile action="upload" filefield="form.FileTwo" destination="#AttachmentDirectory#" nameconflict="makeunique">
9        <cfset FileTwoName = CFFILE.ServerFile>
10        <cfset FileTwo = CFFILE.ServerDirectory & "\" & CFFILE.ServerFile>
11    </cfif>
12    <cfif structKeyExists(form, "FileThree") and form.FileThree is not "">
13        <cffile action="upload" filefield="form.FileThree" destination="#AttachmentDirectory#" nameconflict="makeunique">
14        <cfset FileThreeName = CFFILE.ServerFile>
15        <cfset FileThree = CFFILE.ServerDirectory & "\" & CFFILE.ServerFile>
16    </cfif>

The problem is with the the CFFILE destination. It is set with a relative directory. CF Documentation states:

"Pathname of directory in which to upload the file. If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function."

"If the destination you specify does not exist, ColdFusion creates a file with the specified destination name. For example, if you specify the destination, C:\XYZ, ColdFusion creates a file XYZ in the C: drive."

The simple and correct solution is to set your CFFILE destination as an absolute path:

view plain print about
1<cfset AttachmentDirectory = "G:\www\mysite\uploads" />

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.7. Contact Blog Owner