Attach Files to Email but Don't Store

By: Seth Blanchard | Asked: 10/03/2024
ForumsCategory: General questionsAttach Files to Email but Don't Store
Seth BlanchardSeth Blanchard asked 2 months ago
Is it possible to allow uploads in a form that get attached to an email, but that don't get stored on the site? Maybe it has to be uploaded to attach it, but I'd like to have it removed as soon as the process no longer needed it.  Is there a method for this? Everything works great on the upload and attaching, just want to keep the file from living on the site without manual intervention.
2 Answers
Best Answer
Rob LeVineRob LeVine answered 2 months ago
You can try using frm_after_create_entry to delete the file after the entry is created. The question is whether that hook is called after the notification is triggered. My guess is yes, but you'll have to test it. If the answer is no, you can trigger the notification yourself before deleting the file as seen in this example. If you need to do that, you'll want to disable the notification action so that it doesn't get sent twice.
Seth BlanchardSeth Blanchard answered 2 months ago

Thank you @Rob LeVine I found this code in the link you shared, adapted and added it to the functions.php file using a code plugin. It does allow for files to be attached to email, but does not appear to keep the file in WP. 


add_action('frm_after_create_entry', 'after_entry_created', 50, 2); //use 50 to make sure this is done very last function after_entry_created($entry_id, $form_id){ if($form_id == 5){ //change 5 to the ID of your form $field_id = 25; //change 25 to the ID of the upload field if(isset($_POST['item_meta'][$field_id])){ if(is_array($_POST['item_meta'][$field_id])){ foreach ($_POST['item_meta'][$field_id] as $p){ if(is_numeric($p)) wp_delete_attachment($p, true); } }else if(is_numeric($_POST['item_meta'][$field_id])){ wp_delete_attachment( $_POST['item_meta'][$field_id], true ); } } } }
Rob LeVineRob LeVine replied 2 months ago

Did you verify the file is gone by looking in the wp-content/uploads/formidable/ folder?

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right