Solved

deleting a file after upload and cfmail

Posted on 2009-05-14
3
235 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

861 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

23 Experts available now in Live!

Get 1:1 Help Now