[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

deleting a file after upload and cfmail

Posted on 2009-05-14
3
Medium Priority
?
257 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 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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