Solved

deleting a file after upload and cfmail

Posted on 2009-05-14
3
230 Views
Last Modified: 2013-12-24
I have a form right now on our website where someone can attach a file on a form for recruiting purposes. The file is uploaded then an email is sent to human resources with the attachment.

Right now the file just sits in the server afterwards and needs to be deleted manually every once in a while.

How would I add to the code below to simply delete the file after the email was successfully sent?
<!--- Upload --->

<cfif isdefined('form.FILE')>

<cfif #FORM.FILE# IS NOT "">

<cffile action="upload" FileField="File" destination="#expandPath('./')#upload/"  NameConflict="Makeunique">

</cfif>

</cfif>
 

<!--- email  --->

<cfmail to="email@domain.com" from="website@domain.com" subject="My Subject" type="HTML">

<!--- attach a file if specified --->

<cfif isdefined('form.FILE')>

<CFIF #FORM.FILE# IS NOT "">

<cfmailparam file="#cffile.serverDirectory#\#cffile.serverFile#">

</CFIF></CFIF>

text here

</p>

</cfmail>

Open in new window

0
Comment
Question by:Shawn
3 Comments
 
LVL 19

Expert Comment

by:erikTsomik
Comment Utility
can you add this line after the email get sent
<!--- Upload --->
<cfif isdefined('form.FILE')>
<cfif #FORM.FILE# IS NOT "">
<cffile action="upload" FileField="File" destination="#expandPath('./')#upload/"  NameConflict="Makeunique">
</cfif>
</cfif>
 
<!--- email  --->
<cfmail to="email@domain.com" from="website@domain.com" subject="My Subject" type="HTML">
<!--- attach a file if specified --->
<cfif isdefined('form.FILE')>
<CFIF #FORM.FILE# IS NOT "">
<cfmailparam file="#cffile.serverDirectory#\#cffile.serverFile#">
</CFIF></CFIF>
text here
</p>
</cfmail>
<cffile       action="Delete" file=" file="#cffile.serverDirectory#\#cffile.serverFile#">
0
 
LVL 13

Accepted Solution

by:
usachrisk1983 earned 500 total points
Comment Utility
If you're going to use CFMAIL to delete the attachment once the message is sent, you need to set SPOOLENABLE="NO" within your cfmail tag, if I recall correctly.  Otherwise the file isn't there when ColdFusion is ready to process that message from the spool folder.  This may delay the page from processing since now CFMAIL will wait until the message is sent.  No biggie on a scheduled task, but would be a biggie on a user page.

More info on that here:
http://www.cfnewbie.com/cfnewbie/client/index.cfm/2007/8/18/CFMAIL-Attachment-Missing

You can upload the files to a temporary folder and then delete them on an interval.  An example of this can be found here where it will only delete files that have not been updated in more than 24 hours:

http://www.technicallychris.com/2006/11/07/automatically-cleaning-up-your-coldfusion-temp-files/
0
 
LVL 1

Author Comment

by:Shawn
Comment Utility
yes, I tried cffile action="Delete by itself and was running into this problem. As it is a user page it would be an issue for larger files.

usachrisk1983: your suggestion to delete on an interval is a great idea. thanks for the help.

Shawn

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now