<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Create month and year based folders with Gform_upload_path</title>
		<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path</link>
		<description>Gravity Support Forums Topic: Create month and year based folders with Gform_upload_path</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 22:10:05 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/create-month-and-year-based-folders-with-gform_upload_path" rel="self" type="application/rss+xml" />

		<item>
			<title>sascha on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-42541</link>
			<pubDate>Wed, 30 Nov 2011 07:46:49 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">42541@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks for getting back. In the end I used this code (if someone wants to do something similar):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;//GF to change upload path for forms
add_filter(&#38;quot;gform_upload_path&#38;quot;, &#38;quot;change_upload_path&#38;quot;, 10, 2);
function change_upload_path($path_info, $form_id){
    $form = RGFormsModel::get_form_meta($form_id);  //get form model object
	$post_category_id = $form[&#38;quot;postCategory&#38;quot;]; //I use this to set the post type category
	$post_category_name = get_cat_name($post_category_id);
	echo $form[&#38;quot;postCategory&#38;quot;];
	echo $post_category_name;
    //$upload_dir = wp_upload_dir(); //get wordpress upload directory
    //$dir_base = $upload_dir[&#38;quot;basedir&#38;quot;] . &#38;quot;/gravity_forms/&#38;quot;;
    //$url_base = $upload_dir[&#38;quot;baseurl&#38;quot;] . &#38;quot;/gravity_forms/&#38;quot;;
    	$url_base = site_url() . &#38;quot;/gf_submissions/&#38;quot;; // use directory outside WP - needs the &#38;quot;/&#38;quot; at the beginning
   	$dir_base = ABSPATH . &#38;quot;gf_submissions/&#38;quot;; // use directory outside WP - does not need the &#38;quot;/&#38;quot; at the beginning
    $current_user = wp_get_current_user(); //get current wordpress user information
    if ( 0 == $current_user-&#38;gt;ID ) {
      //user is not logged in; set default values
      $user_level = &#38;quot;not_logged_in&#38;quot;;
      $user_login = &#38;quot;not_logged_in&#38;quot;;
    }
    else {
      //user is logged in
      $user_role = get_current_user_role(); // calls my own function -&#38;gt; get_current_user_role
      $user_login = $current_user-&#38;gt;user_login;
    }
	//get post title from form ----- be careful with field ID!!!
	$post_title = $_POST[&#38;#39;input_1&#38;#39;];
	//cleaning it - not sure if that is a great way?????
	$post_title = trim($post_title);
	$post_title = preg_replace(&#38;#39;&#38;lt;code&#38;gt;[^a-z0-9_]&#38;lt;/code&#38;gt;i&#38;#39;,&#38;#39;&#38;#39;,strtolower(ereg_replace(&#38;quot; &#38;quot;,&#38;quot;_&#38;quot;,$post_title)));
	$post_title = trim(ereg_replace( &#38;#39;_+&#38;#39;, &#38;#39;_&#38;#39;, $post_title));

    //set variable to form title, 4 digit year, 2 digit month, user level (numeric), user login
    //$subfolders = $form[&#38;quot;title&#38;quot;].&#38;quot;/&#38;quot;.date(&#38;quot;Y&#38;quot;).&#38;quot;/&#38;quot;.date(&#38;quot;m&#38;quot;).&#38;quot;/&#38;quot;.$user_level.&#38;quot;/&#38;quot;.$user_login.&#38;quot;/&#38;quot;;
    	$subfolders = $post_category_name.&#38;quot;/&#38;quot;.$user_role.&#38;quot;/&#38;quot;.$user_login.&#38;quot;/&#38;quot;.$post_title.&#38;quot;/&#38;quot;;
	$path_info[&#38;quot;path&#38;quot;] = $dir_base.$subfolders; //set path
    $path_info[&#38;quot;url&#38;quot;] = $url_base.$subfolders; //set url
    return $path_info;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>Dana Cobb on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-42378</link>
			<pubDate>Mon, 28 Nov 2011 20:13:30 +0000</pubDate>
			<dc:creator>Dana Cobb</dc:creator>
			<guid isPermaLink="false">42378@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi, Sascha,&#60;/p&#62;
&#60;p&#62;I was off for the holiday and took a look at your responses today. I wasn't sure if you still needed some help because it looked like you answered a lot of your own questions. If you do still have questions that aren't specific to creating folders using the month/year as the topic title mentions, I think you should create a new topic as Chris suggested. This way others will benefit when searching for issues related to your new topic which may otherwise be buried in the upload folder creation topic.&#60;/p&#62;
&#60;p&#62;Thanks!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-42162</link>
			<pubDate>Fri, 25 Nov 2011 05:45:07 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">42162@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Dana,&#60;br /&#62;
of course you used the form object model! Sometimes I'm just blind...&#60;br /&#62;
And of course I need to get a field value from the current form by field ID.&#60;br /&#62;
Have a great day,&#60;br /&#62;
Sascha
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-42157</link>
			<pubDate>Fri, 25 Nov 2011 04:34:50 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">42157@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hello Dana again,&#60;/p&#62;
&#60;p&#62;Other &#34;dirty&#34; option maybe???&#60;br /&#62;
I know the post title is available during:&#60;br /&#62;
 public static function create_post($form, &#38;amp;$lead) (in forms_model.php)&#60;br /&#62;
I saved it once (some months ago) adding at around 1484 - just before //inserting post&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;//SASCHA defining variables------------------------------------------------------------------------------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxx-----------------------
		global $post_title_from_form;
		$post_title_from_form = $post_data[&#38;quot;post_title&#38;quot;];&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;It's not ideal, but I do not mind adding that code on each update :)&#60;br /&#62;
That $post_title_from_form is then available in get_file_upload_path (where the gform_upload_path filter is located) at around 1885 when I insert:&#60;br /&#62;
&#60;code&#62;global $post_title_from_form;&#60;/code&#62;  and then insert/replace:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;$target_root = self::get_upload_path($form_id) . &#38;quot;/$currentuserrole/$currentusername/$formtitle/$post_title_from_form/&#38;quot;;
$target_root_url = self::get_upload_url($form_id) . &#38;quot;/$currentuserrole/$currentusername/$formtitle/$post_title_from_form/&#38;quot;;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Before I knew about the filter I &#34;hardcoded&#34; that path using $post_title_from_form as above (after I cleaned it up of course). Again that is not ideal! I rather use the filter!&#60;br /&#62;
Is there a way of somehow making that variable ($post_title_from_form) available in your filter function change_upload_path from your snippet? Then all I need to do is put in those lines defining that variable each time I update...&#60;/p&#62;
&#60;p&#62;Anyway, any pointers would be great, as I am &#34;desperate&#34; to keep the uploaded files/images together in a directory based on the post title!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-42155</link>
			<pubDate>Fri, 25 Nov 2011 03:38:54 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">42155@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Dana,&#60;br /&#62;
thanks for the code! It is very clean and easy to understand, thanks to all your comments!&#60;br /&#62;
Is there any way to get a form field by ID then ? I can get the &#34;post title&#34; by doing that. I just have to make sure the post title field is always the same ID in each form or create filters for different forms (which I might do anyway).&#60;/p&#62;
&#60;p&#62;One question though:&#60;/p&#62;
&#60;p&#62;Why do you get the form model object? You do not seem to use it?&#60;br /&#62;
$form = RGFormsModel::get_form_meta($form_id);  //get form model object&#60;br /&#62;
Is all the form data in there?&#60;/p&#62;
&#60;p&#62;Or would I need to get the entry model object? If so, how would I go about this?&#60;/p&#62;
&#60;p&#62;Other question: should I open a new ticket again (other one was closed) or is it enough that the other ticket points to this one?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Dana Cobb on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-42037</link>
			<pubDate>Wed, 23 Nov 2011 17:55:13 +0000</pubDate>
			<dc:creator>Dana Cobb</dc:creator>
			<guid isPermaLink="false">42037@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi, Sascha,&#60;/p&#62;
&#60;p&#62;In response to your first question, the link below will give you an example of how to create the new folders for the form title, year, month, user level, and user name using the gform_upload_path hook.&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastie.org/2911174&#34; rel=&#34;nofollow&#34;&#62;http://pastie.org/2911174&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;As far as getting the post title, this is not possible using the gform_upload_path hook because the post is not created when this hook fires.&#60;/p&#62;
&#60;p&#62;Let me know if you have questions about the code provided.&#60;/p&#62;
&#60;p&#62;Have fun!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-41956</link>
			<pubDate>Wed, 23 Nov 2011 00:05:00 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">41956@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;sascha, please start a new topic for your request to get the form title and post title.  Those issues are unrelated to this topic, and it makes searching for solutions hard when they're buried in an unrelated topic like this.  We'll be happy to help you with your request.  Thank you.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-41927</link>
			<pubDate>Tue, 22 Nov 2011 19:03:19 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">41927@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi again,&#60;br /&#62;
folders do get created automatically. So that is all good. How do I go about getting the &#34;form title&#34; and the &#34;post title&#34; (I am submitting a post), so I can add those to my function for the filter?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Create month and year based folders with Gform_upload_path"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-month-and-year-based-folders-with-gform_upload_path#post-41873</link>
			<pubDate>Tue, 22 Nov 2011 11:52:36 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">41873@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi there,&#60;br /&#62;
is there a way to create year and month based folders with the Gform_upload_path filter? Obviously the folders need to be created as they will change ever so often.&#60;br /&#62;
Ideally I would base the upload folder on:&#60;br /&#62;
form title/year/month/user_role/user_name&#60;/p&#62;
&#60;p&#62;The main thing I need to know is how to create the folders. The rest I can put together in a function. But a little example based on the form title for instance will get me going the right way!&#60;br /&#62;
Many thanks,&#60;br /&#62;
Sascha
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
