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

ColdFusion Language

Avatar of undefined
Last Comment
earwig75

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Tomarse111

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
earwig75

ASKER
This worked, thank you.

<cfmailparam file="#attachment_local_file_1#" remove="true">
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes