troubleshooting Question

How to delete files from server after uploading with cold fusion

Avatar of earwig75
earwig75 asked on
ColdFusion Language
2 Comments1 Solution335 ViewsLast Modified:
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>
ASKER CERTIFIED SOLUTION
Tomarse111

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros