<?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: File upload location and name</title>
		<link>https://legacy.forums.gravityhelp.com/topic/file-upload-location-and-name</link>
		<description>Gravity Support Forums Topic: File upload location and name</description>
		<language>en-US</language>
		<pubDate>Sat, 04 Apr 2026 16:22:39 +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/file-upload-location-and-name" rel="self" type="application/rss+xml" />

		<item>
			<title>David Peralty on "File upload location and name"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/file-upload-location-and-name#post-76122</link>
			<pubDate>Tue, 18 Sep 2012 16:14:48 +0000</pubDate>
			<dc:creator>David Peralty</dc:creator>
			<guid isPermaLink="false">76122@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Very awesome, thanks for doing this!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bristweb on "File upload location and name"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/file-upload-location-and-name#post-76119</link>
			<pubDate>Tue, 18 Sep 2012 16:03:38 +0000</pubDate>
			<dc:creator>bristweb</dc:creator>
			<guid isPermaLink="false">76119@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I've seen several posts ask this, but no simple answer.  here is how you can rename files upon upload&#60;/p&#62;
&#60;p&#62;ex: we want to change the files for form 9&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;quot;gform_upload_path&#38;quot;, &#38;quot;custom_upload_path&#38;quot;, 10, 2); //this is a gf filter which changes the upload path
function custom_upload_path($path_info, $form_id){
	if($form_id==9){
		$path_info[&#38;quot;path&#38;quot;] = &#38;quot;/home/youruser/public_html/wp-content/uploads/customfolder/&#38;quot;;
		$path_info[&#38;quot;url&#38;quot;] = &#38;quot;http://example.com/wp-content/uploads/customfolder/&#38;quot;;
	}
	return $path_info;
}

add_action(&#38;quot;gform_after_submission_9&#38;quot;, &#38;quot;custom_after_submission_9&#38;quot;, 10, 2); //this is a gf filter which lets us get an entry after it is done.  we will use this to automatically rename files (only form 9 in the example)
function custom_after_submission_9($entry, $form){
    foreach($form[&#38;#39;fields&#38;#39;] as $key =&#38;gt; $field){  //this will get all the fields that are a fileupload type
	    if($field[&#38;#39;type&#38;#39;] == &#38;#39;fileupload&#38;#39;)
	    	$keys[] = $field[&#38;#39;id&#38;#39;];
    }
    foreach($keys as $value){  //this will save the url info for all the fields which were submitted
    	$pathinfo = pathinfo($entry[$value]);
    	if(!empty($pathinfo[&#38;#39;extension&#38;#39;])){
	    	$oldurls[$value] = $pathinfo;
	    	$pathinfo[&#38;#39;filename&#38;#39;] = $entry[&#38;#39;id&#38;#39;] . &#38;#39;_&#38;#39; . $form[&#38;#39;id&#38;#39;] . &#38;#39;_&#38;#39; . $value;  //we are going to make the files look something like this entryid_formid_fieldid... so you may have something like 323_9_12 for the filename.   this system ensures all filenames are unique and sorted.  you can make the name anything you like.  remember it is the filename only (no path and no extension)
	    	$newurls[$value] = $pathinfo;
    	}
    }
    $uploadinfo = custom_upload_path(&#38;#39;&#38;#39;, 9); //this will get the upload path from our custom filter
    foreach($newurls as $key =&#38;gt; $value){
    	$oldpath = $uploadinfo[&#38;#39;path&#38;#39;].$oldurls[$key][&#38;#39;filename&#38;#39;].&#38;#39;.&#38;#39;.$oldurls[$key][&#38;#39;extension&#38;#39;];
    	$newpath = $uploadinfo[&#38;#39;path&#38;#39;].$newurls[$key][&#38;#39;filename&#38;#39;].&#38;#39;.&#38;#39;.$newurls[$key][&#38;#39;extension&#38;#39;];
    	$oldurl = $uploadinfo[&#38;#39;url&#38;#39;].$oldurls[$key][&#38;#39;filename&#38;#39;].&#38;#39;.&#38;#39;.$oldurls[$key][&#38;#39;extension&#38;#39;];
    	$newurl = $uploadinfo[&#38;#39;url&#38;#39;].$newurls[$key][&#38;#39;filename&#38;#39;].&#38;#39;.&#38;#39;.$newurls[$key][&#38;#39;extension&#38;#39;];
    	$is_success = rename($oldpath,$newpath); //this renames the file
    	if($is_success &#38;amp;&#38;amp; !empty($is_success)){
	    	global $wpdb;
	    	$wpdb-&#38;gt;update(RGFormsModel::get_lead_details_table_name(), array(&#38;quot;value&#38;quot; =&#38;gt; $newurl), array(&#38;quot;lead_id&#38;quot; =&#38;gt; $entry[&#38;quot;id&#38;quot;], &#38;quot;value&#38;quot; =&#38;gt; $oldurl)); //this updates wordpress
    	}
    }
    return;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
