Normally uploads in a Gravity Form are stored in the same folder. This is a problem when uploaded files are privacy sensitive and you want to share the links to files with people who filled in a form. They know the way to the folder, so they can get access to files from others (merely by guessing). Thankfully, it is possible to create unique folders for each upload.
How to save user uploads in a Gravity Form to separate folders?
Normally all file uploads via one Gravity Form are placed in a folder like:
wp-content/uploads/gravity_forms/1-b41819ae08fb08e6d3825745519c5748/2014/08
To store every upload into it’s own folder you can add the following code in your functions.php in your template folder:
add_filter("gform_upload_path", "change_upload_path", 10, 2);
function change_upload_path($path_info, $form_id){
$uniqueid = uniqid('your-reference', true);
$path_info["path"] = "/home/gravitywp/domains/gravitywp.com/public_html/uploads/$uniqueid/";
$path_info["url"] = "https://gravitywp.com/uploads/$uniqueid/"; return $path_info;
}
- your-reference: you can fill in anything you like here. Every folder will start with this text.
- $path_info[“path”]: fill in the full physical path to the upload folder and use the created $uniqueid variable to create unique folder names.
- $path_info[“url”]: fill in the full URL to the upload folder.
When you now upload a file in a form it will now generate an unique folder for each upload. For example:
https://gravitywp.com/uploads/your-reference554338385546f2374182415/example-file.pdf
Apache folder problem
When you create a folder for every file that is uploaded in Gravity Forms on your site, it’s possible (especially when you have a lot of people uploading files in your forms) that you create too many folders for Apache to handle. At a certain moment, Gravity Forms won’t be able to create a new folder for the upload and the upload will fail. There is quite a simple solution for this, because we know now how to create a filter for our uploads. Just add the following to your functions.php (instead of the above code):
add_filter("gform_upload_path", "change_upload_path", 10, 2);
function change_upload_path($path_info, $form_id){
$uniquefolder = rand(1,9999);
$uniqueid = uniqid('your-reference', true);
$path_info["path"] = "/home/gravitywp/domains/gravitywp.com/public_html/uploads/$uniquefolder/$uniqueid/";
$path_info["url"] = "https://gravitywp.com/uploads/$uniquefolder/$uniqueid/"; return $path_info;
}
The new variable added is $uniquefolder.
$uniquefolder = rand(1,9999);
This will pick a random number between 1 and 9999 and create this folder for us. If the folder exist, it will place our unique folder inside this ‘number folder’. This way you multiplied the number of available slots by 10.000. You have a very successful website when you beat that.
Use the Form ID as folder name for uploads
A nice extra would be to add the Form ID of the form people upload documents in to the upload path. This is quite easy and also makes it less likely that you run out of available space on your server. You just add a third variable that is already available, because you are using it in combination with Gravity Forms: $form_id (look also to the arguments passed in the function):
add_filter("gform_upload_path", "change_upload_path", 10, 2);
function change_upload_path($path_info, $form_id){
$uniquefolder = rand(1,9999);
$uniqueid = uniqid('your-reference', true);
$path_info["path"] = "/home/gravitywp/domains/gravitywp.com/public_html/uploads/$form_id/$uniquefolder/$uniqueid/";
$path_info["url"] = "https://gravitywp.com/uploads/$form_id/$uniquefolder/$uniqueid/"; return $path_info;
}
As you can see now you have three levels of folders you create for every upload:
.../uploads/$form_id/$uniquefolder/$uniqueid/"; .../uploads/$form_id/$uniquefolder/$uniqueid/"; return $path_info;
Use relative $path_info
There is a simple way to use WordPress core functionality to find your current upload path and url. Just use this code instead of the hard coded path and url:
add_filter("gform_upload_path", "change_upload_path", 10, 2);
function change_upload_path($path_info, $form_id) {
$uniqueid = uniqid('your-reference', true);
$path_info["path"] = WP_CONTENT_DIR . "/files/";
$path_info["url"] = WP_CONTENT_URL . "/files/";
return $path_info;
}
This way uploads will be placed automatically in https://yourdomain.io/files/
Using entry data in upload path Gravity Forms
You can also use data from fields in the entry to create a unique upload path or structure your uploads. You can access the data with:
rgpost( 'input_3'
Where the field_id is 3, you use input_3. If you want data from an advanced field with multiple inputs, you can use:
rgpost( 'input_3_2'
This way you can get data from a specific subfield in for example the name or address field.
add_filter("gform_upload_path", "change_upload_path", 10, 2);
function change_upload_path($path_info, $form_id){
$category = sanitize_title(rgpost( 'input_3' ));
$title = sanitize_title(rgpost( 'input_2' ));
$path_info["path"] = WP_CONTENT_DIR . "/files/" . $category . "/" . $title . "/";
$path_info["url"] = WP_CONTENT_URL . "/files/" . $category . "/" . $title . "/";
return $path_info;
}
Be aware to sanitize the input you use for the upload path / url. We advise to use the sanitize_title function from WordPress:
sanitize_title(rgpost( 'input_3' ))
This way you’ll be sure the value being used is suited to use as folder name.
Read tutorials about
n8n vs Zapier: Which Automation Tool Actually Fits Your Work?
Trying to decide between n8n vs Zapier? This article breaks down pricing, hosting, integrations, AI features, and where self-hosted n8n on a cheap VPS can beat Zapier’s task-based plans. You’ll also see how Gravity Forms users can plug in the GravityWP n8n Connector and move key workflows off Zapier without rebuilding their forms.
Cloudflare Tunnel + n8n: Expose Local n8n for Webhook Testing (Dev Only)
This guide shows how to use Cloudflare Tunnel Quick Tunnels to put a local n8n instance on the internet for real webhook testing. It’s a dev-only recipe that lets tools like GravityWP’s n8n Connector call your local n8n over HTTPS, without renting a VPS or opening ports.
Self-Host n8n with Docker on a VPS
Learn how to self-host n8n with Docker on a VPS using a production-ready setup. This step-by-step guide walks you through configuring Docker Compose, Postgres, HTTPS, and WEBHOOK_URL so you can run reliable, secure n8n workflows on your own server.
One-Click n8n Hosting: How to Deploy n8n with Railway, Elestio & Coolify
Learn how one-click n8n hosting works on platforms like Railway, Elestio, and Coolify. This guide explains when to pick one-click hosting over n8n Cloud or a raw VPS, how templates are structured, and which env vars, security settings, and troubleshooting tips you can’t skip.