Hi! When we have a form that uses a file upload field we need to save that file to an upload folder on the server in order to be able to send it as an attachment with an e-mail. Is there a way to delete the file after the mail has been send so this upload folder will not fill up?
Kind regards,
Jip
Thanks healyhatman. we'll try to add a custom PHP action in the 'success' part of the mail send action.
It might be easier for CF6 users to have an action for this though...
Mmmm, there is no 'success' or 'fail' area inside the e-mail action ;-)
We could add the custom PHP action after the mail action , but I think that might maybe interfere with the sending of the email... I'm not sure if this custom code will 'wait' for the email to be send.
Maybe. I can whip something up but it'll a) cost you a few dollars and b) be your fault if you put the wrong thing in the delete file path and delete your website.
The code won't be run until after the email sends, that's not a problem.
Yes, it might be risky ;-) Maybe adding an option to the save files action or adding a new action to CF might be a better idea then using custom scripting. So I's leave this as a feature request for CF6 for now. Thanks for your input healyhatman.
As an alternative we can maybe use Cache Cleaner (Regular Labs) to clean the upload folder. Or use a cron script to do this. But we have to be careful not to clean the folder at the same time someone is using it on the site...
Nah that shouldn't be a problem. I have a cron job that runs a PHP script that deletes all images older than 7 days from my temp folder.
Adding it to the file upload action is a non-starter, because how is it supposed to know WHEN to delete the file?