Hi @karma9999
I hope you’re well today!
The submission data is by default stored in the database on site but you can disable that option (for each form separately, in a form “Settings” section).
The files, however, are always uploaded to the server. They can be send as attachments, you can decide whether to add them to Media Library or not and you can set submission retentions (in form “Settings -> Data” section in “Privacy” options) so each submission that’s stored in DB would be automatically deleted after defined time. This may include deleting uploaded files.
But still, when the form is submitted the file will be uploaded to server and will stay there until it’s either manually removed or automatically removed due to forms Privacy settings.
If you want to have them removed right away after the e-mail was sent then you need to make sure that upload field is set to not add files to Media Library and you would need to use additional code:
<?php
/*
* Delete upload after email is sent
* Author: Paul
*/
if ( ! defined( 'ABSPATH' ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
return;
}
add_action( 'forminator_custom_form_mail_admin_sent', 'delete_upload_after_email', 99, 5 );
function delete_upload_after_email( $instance, $custom_form, $data, $entry, $recipients ) {
foreach ( $entry->meta_data as $field_name => $field ) {
if ( false !== strpos( $field_name, 'upload' ) ) {
foreach ( $field['value']['file'] as $key => $value ) {
if ( 'file_path' === $key && ! empty( $value ) ) {
if ( is_array( $value ) ) {
foreach ( $value as $path ) {
wp_delete_file( $path );
}
} else {
wp_delete_file( $value );
}
}
}
}
}
}
You’d need to add it to the site as MU plugin:
– create an empty file with a .php extension (e.g “formiantor-delete-files.php”)
– copy and paste that code into it and save the file
– upload it to the “/wp-content/mu-plugins” folder of your site’s WordPress installation
Best regards,
Adam
Thanks for your best support possible. You cleared all my doubts.