Solved

deleting a file after upload and cfmail

Posted on 2009-05-14
3
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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