Solved

deleting a file after upload and cfmail

Posted on 2009-05-14
3
242 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
ID: 24387504
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
ID: 24391855
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
ID: 24403383
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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