Gravity Forms allows file uploads as part of a form submission. Lucas Stark’s WooCommerce Gravity Forms add-on allows file uploads to be attached to products in WooCommerce. These files are stored in the uploads folder, in subfolders containing long alphanumeric strings to prevent unauthorised access. For example:
/public_html/wp-content/uploads/gravity_forms/16-f57410eca19713ef56bc4faab7a7c1e6d/2014/11
If you are getting a lot of uploads, the server space used by the files can quickly mount up, requiring some regular housekeeping to free up space.
Manually removing expired form entries
Once you have finished with the submitted forms you can remove them from the admin interface.
- Go to Forms in admin.
- Click on the number of entries in the Entries column for the form you are working with.
- In the search filter, select Entry Date + less than and enter a cutoff date in the format YYYY/MM/DD. e.g to delete entries older than 01/04/2014 enter 2014/04/01.
- Click Search.
- Select the checkbox under the Bulk action drop down to select all the entries. Click the Select all XXX entries link that appears.
- In the Bulk action drop down, select Trash and click Apply.
- Click the Trash link at the top of the list.
- Select the checkbox under the Bulk action drop down. Select the Delete Permanently bulk action and click Apply to delete the entries permanently from the Trash.
Notes:
- Use the Switch Form drop down to select the correct form.
- Removing entries in this way also deletes the files uploaded with each entry.
Beware: Once the entries have been permanently deleted from the trash, they cannot be recovered.
Automatically removing expired Gravity Forms entries
Travis Lopes’ Entry Expiration For Gravity Forms does a nice job of clearing out entries after a set period. Uploaded files are deleted when the form entry is deleted.
As the clear out process is triggered by wp_cron, you may want to set up a proper cron job to trigger wp_cron if you don’t get much traffic to your site.
Removing temporary files
Gravity Forms stores uploaded files in a temporary folder while they are uploading, before transferring them to their final location. If the upload process doesn’t complete for some reason, you can end up with a bunch of files in the tmp folder. For example:
/public_html/wp-content/uploads/gravity_forms/16-f57410eca19713ef56bc4faab7a7c1e6d/tmp
It is probably safe to remove files in the tmp folder that are more than say 3 days old. To do this, SSH into your server space and run the following command:
find public_html/wp-content/uploads/gravity_forms/*/tmp* -mtime +3 -exec rm -f {} \;
Notes:
- The path contains wildcards to match the Gravity Forms folder pattern.
- -mtime +3 means find files with date modified greater than 3 days ago.
- -exec rm -f {} executes a delete on matched files only.
Update 26/09/2016: It might be best to leave these in place. GF uses the tmp folder to store entries which have been saved for later completion. Thanks for the tip Shaun!
Hello, i’ve an installation of gravity forms active since 2012. Now the entries with upload files field used really too much. I need to clean. I deleted the entries as you mention but seems many files stays in the folder. Is it safe to clean old folder directly from ftp? The number of actual entries can’t justify the used space. Yes, i emptied the trash.
Thank you
Very Nice Niall Flynn
I think a setup to store these offsite, DropBox/Google Drive etc would be a good patch, if the docs uploaded are sensitive too it might not be a good idea to leave uploads on your own server.
Well, that’s moot really. If someone gets access to your web server’s filesystem to access the uploads, they will also probably be able to access anything else, including any oauth details for Google/Dropbox etc. There is a plugin which attaches the uploads to the notification email and has an option to delete the files after sending. But is email secure either?
Probably the best strategy is to keep your site up to date, run a security plugin/firewall and do regular housekeeping to delete uploaded files after you’ve finished with them.
Thanks for the information Niall. It shows that answering your own comments is actually a helpful thing as this was just what I was looking for. Once again, thanks.
I think a setup to store these offsite, DropBox/Google Drive etc would be a good patch, if the docs uploaded are sensitive too it might not be a good idea to leave uploads on your own server.
And I just discovered it exists already and is native to GF 🙂 http://www.gravityforms.com/add-ons/dropbox/ I think all up storing this on server is a bad idea, especially if the form is employment/HR based CVs, document scans etc.
Yes agreed, having sensitive files sitting around on the server is never a good idea. In the past, I’ve used the GF Upload to Email Attachment plugin to send the uploads as attachments to the admin notification email, and Gravity Forms Entry Expiration to remove form entries (including uploaded files) after a set period of time.
This temp folder also includes files from entries that have been saved for later. You will need to ensure that you check to make sure that the files do not correspond to an incomplete entry that the user can finish submitting later.
Ah, I did not know that. I thought it was only abandoned entries. Well, maybe we can trust that Gravity Forms does regular garbage collection to clear out abandoned entries then. Thanks for pointing this out.