Link to home
Start Free TrialLog in
Avatar of earwig75
earwig75

asked on

How to delete files from server after uploading with cold fusion

I am using the below method to upload and email 3 files. I would like to delete the files from the server after the email is sent. Could someone assist with the code? Thank you.

<!--- Make sure that the user uploaded attachments --->
<cfif FORM.attachment_1 neq "">
       <!--- first actually upload the file --->
       <cffile action="upload"
                 filefield="attachment_1"
                 destination="d:\upload\"
                 nameconflict="Makeunique">
        <!--- create a temporary holder for the attachment later on --->
        <cfset attachment_local_file_1 = "d:\upload\#file.serverfile#">
</cfif>

<cfif FORM.attachment_2 neq "">
       <!--- first actually upload the file --->
       <cffile action="upload"
                 filefield="attachment_2"
                 destination="d:\upload\"
                 nameconflict="Makeunique">
        <!--- now create a temporary holder for the attachment later on --->
        <cfset attachment_local_file_2 = "d:\upload\#file.serverfile#">
</cfif>
<cfif FORM.attachment_3 neq "">
       <!--- first actually upload the file --->
       <cffile action="upload"
                 filefield="attachment_3"
                 destination="d:\upload\"
                 nameconflict="Makeunique">
        <!--- now create a temporary holder for the attachment later on --->
        <cfset attachment_local_file_3 = "d:\upload\#file.serverfile#">
</cfif>

<cfmail from="from@fromaddy.com" to="#form.to_addr#" subject="#subject#" >
    #message#

   <cfsilent>


     <cfif FORM.attachment_1 neq "">
        <cfmailparam file="#attachment_local_file_1#">
     </cfif>
     <cfif FORM.attachment_2 neq "">
        <cfmailparam file="#attachment_local_file_2#">
     </cfif>
     <cfif FORM.attachment_3 neq "">
        <cfmailparam file="#attachment_local_file_3#">
     </cfif>
   </cfsilent>
</cfmail>

Open in new window

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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of earwig75
earwig75

ASKER

This worked, thank you.

<cfmailparam file="#attachment_local_file_1#" remove="true">