Unique path for every upload Gravity Forms

GravityWPGravityForms0 Comments

The files people upload in a Gravity Form are placed in the same folder.
(Looks something like: wp-content/uploads/gravity_forms/1-b41819ae08fb08e6d3825745519c5748/2014/08).

This is a problem when uploaded files are privacy sensitive and you when 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. Thankfully, it is possible to create unique folders for each uploaded file.

 

You can use the code here in your functions.php in your template folder:

<pre>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; 
   }

When you upload a file in a form it will generate an unique folder for each upload. For example:

https://gravitywp.com/uploads/your-reference554338385546f2374182415/example-file.pdf

 

Take into account:

  1. your-reference: you can fill in anything you like here. Every folder will start with this text.
  2. $path_info[“path”]: fill in the full physical path to the upload folder and use the created $uniqueid variable to create unique folder names.
  3. $path_info[“url”]: fill in the full URL to the upload folder.

Download Gravity Forms and try it out

Share this Post