Title: Delete file after email?
Last modified: August 30, 2016

---

# Delete file after email?

 *  Resolved [deargeek](https://wordpress.org/support/users/deargeek/)
 * (@deargeek)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/delete-file-after-email/)
 * Great plugin, thank you 🙂
 * Is there a way the uploaded file(s) could be deleted after them being emailed?
 * I don’t want to keep copies of the files uploaded on the server.
 * Thanks!
 * [https://wordpress.org/plugins/gf-upload-to-email-attachment/](https://wordpress.org/plugins/gf-upload-to-email-attachment/)

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/delete-file-after-email/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/delete-file-after-email/page/2/?output_format=md)

 *  Plugin Author [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * (@billiardgreg)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385184)
 * I will look into a way to allow that. I want to create a settings page for this
   add-on to allow zipping control as well. As it is usually saved with the entry
   in Gravity Forms I figured it was a good idea to leave them there to not mess
   anything up with that. Only issue with this I see is if the email happens to 
   fail for some reason or not get delivered the attachment would then be lost. 
   What if in the outbound email a link gets created that says delete files from
   server?
 *  Thread Starter [deargeek](https://wordpress.org/support/users/deargeek/)
 * (@deargeek)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385286)
 * That would be great.
 * For what I’m using it for, asking the recipient to delete from the server would
   be a bit too much for their skill level. Equally, we’d rather risk losing the
   attachment than have a copy left on the server.
 * I suppose I could set something up in the cron to empty out the folder, but a
   tickbox would be so much easier 😉
 *  [jdestree](https://wordpress.org/support/users/jdestree/)
 * (@jdestree)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385361)
 * I am looking for the same feature.
 *  Plugin Author [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * (@billiardgreg)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385438)
 * I created a 1.4 version which is in beta but it attempts to delete the files 
   in the gravity forms storage area at the same time as the zip file is deleted.
   You can look at version 1.4 at [http://plugins.svn.wordpress.org/gf-upload-to-email-attachment/tags/1.4/](http://plugins.svn.wordpress.org/gf-upload-to-email-attachment/tags/1.4/)
   to which the gf-upload-to-email-attachment.php has the following changes:
 *     ```
       function gfuea_clean_zips($confirmation, $form, $entry, $ajax) {
       	$notifications = $form['notifications'];
       	$gfueaFound = false;
   
       	foreach ($notifications as $notification) {
       		$last5 = substr($notification["name"],-5);
       		$last7 = substr($notification["name"],-7);
       		if($last5 == "GFUEA" || $last7 == "GFUEANZ") {
       			$gfueaFound = true;
       		}
       	}
   
       	if ($gfueaFound = true) {
       		$upload_root = RGFormsModel::get_upload_root();
   
       		$filename = $upload_root . "/uploaded_files".$entry['id'].".zip";
       		if (is_file($filename)){
       			unlink($filename);
       		}
   
       		//delete files from server
       		$fileupload_fields = GFCommon::get_fields_by_type( $form, array( 'fileupload' ) );
       		foreach( $fileupload_fields as $field ) {
       			$url = $entry[ $field['id'] ];
       			if ( empty( $url ) ) {
       				continue;
       			} elseif ( $field['multipleFiles'] ) {
       				$uploaded_files = json_decode( stripslashes( $url ), true );
       				foreach ( $uploaded_files as $uploaded_file ) {
       					$attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $uploaded_file );
       					unlink($attachment);
       				}
       			} else {
       				$attachment = preg_replace( '|^(.*?)/gravity_forms/|', $upload_root, $url );
       				unlink($attachment);
       			}
       		}
       		//end delete files from server
       	}
   
       	return $confirmation;
       }
       ```
   
 * Please let me know how it works for you and I will be looking into how to modify
   the notifications options to try to get choices in there.
 *  Plugin Author [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * (@billiardgreg)
 * [10 years, 8 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385442)
 * Anyone happen to have a chance to test out this beta?
 *  [joshuabaer23](https://wordpress.org/support/users/joshuabaer23/)
 * (@joshuabaer23)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385476)
 * What a neat idea, but all I can think of is the possible downfalls. I can not
   let any of my staff permission to delete anything…or Id loose it forever.
    Seems
   this would be best as an Admin permissions thing from WP itself. Maybe another
   plugin.
 *  Plugin Author [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * (@billiardgreg)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385477)
 * Yea, that is why it is in beta right now. I didn’t want to release it as a integrated
   feature yet. But giving people the opportunity to test it if they wanted too.
   I will want to integrate it with the ability for people to turn it on if they
   want.
 *  [FGD](https://wordpress.org/support/users/creativetopia/)
 * (@creativetopia)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385490)
 * I gave this a go but the image was not deleted from the server.
 *  Plugin Author [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * (@billiardgreg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385491)
 * Please post what version you installed, also anything in the error_log as to 
   why its unable too? like an unlink problem.
 *  [Jebble](https://wordpress.org/support/users/jebble/)
 * (@jebble)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385495)
 * I just tested 1.4 on WP 4.3.1 with Gravity Forms 1.9.14 and it does not delete
   the uploaded file(s)
 *  Plugin Author [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * (@billiardgreg)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385496)
 * Is there anything in the error_log file of the testing location? But I guess 
   that this is why this isn’t the released version yet.
 *  [199ah](https://wordpress.org/support/users/199ah/)
 * (@199ah)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385497)
 * love this plugin allowing me to receive uploaded files as an email attachment!
   
   A recent user’s files were uploaded and I received a notification without the
   attachment. I did find them in the form entries area however.
 * When I tried to resend the notification I get this error:
 * Fatal error: Allowed memory size of 62914560 bytes exhausted (tried to allocate
   43275709 bytes) in /homepages/26/d598859973/htdocs/clickandbuilds/ForSaleByOwnerListings/
   wp-includes/class-phpmailer.php on line 2393
 * also deleted the files in the wp-content/uploads/gravity_forms directory but 
   I still get this error message
 *  [199ah](https://wordpress.org/support/users/199ah/)
 * (@199ah)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385498)
 * is that beta working- I don’t have much experience (please be patient!)but will
   test it out- where exactly does the code go?
 * where do the uploaded files reside in wp directory? In the mean time I can manually
   delete theme once downloaded.
 *  Plugin Author [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * (@billiardgreg)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385499)
 * If you use the above code it will delete the file after attempting to attach 
   it to the email. This is currently a beta and if you use the one in the plugin
   repository it will not delete the files and should be attached with the form 
   in gravity forms. That error message has to do with the 64mb of memory. What 
   size file are you trying to attach?
 *  [graphems](https://wordpress.org/support/users/graphems/)
 * (@graphems)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/delete-file-after-email/#post-6385511)
 * You can also simply delete the entry, which delete the files at the same time,
   like this:
 *     ```
       add_action( 'gform_after_submission_3', 'remove_form_entry', 100, 2 );
       function remove_form_entry( $entry, $form ) {
           GFAPI::delete_entry( $entry['id'] );
       }
       ```
   
 * where gform_after_submission_3 refers to the form id

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/delete-file-after-email/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/delete-file-after-email/page/2/?output_format=md)

The topic ‘Delete file after email?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gf-upload-to-email-attachment.svg)
 * [GF Upload to Email Attachment](https://wordpress.org/plugins/gf-upload-to-email-attachment/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gf-upload-to-email-attachment/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gf-upload-to-email-attachment/)
 * [Active Topics](https://wordpress.org/support/plugin/gf-upload-to-email-attachment/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gf-upload-to-email-attachment/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gf-upload-to-email-attachment/reviews/)

 * 20 replies
 * 9 participants
 * Last reply from: [WP CMS Ninja](https://wordpress.org/support/users/billiardgreg/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/delete-file-after-email/page/2/#post-6385520)
 * Status: resolved