<?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: Renaming uploaded files before saving</title>
		<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving</link>
		<description>Gravity Support Forums Topic: Renaming uploaded files before saving</description>
		<language>en-US</language>
		<pubDate>Fri, 17 Apr 2026 01:56:11 +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/renaming-uploaded-files-before-saving" rel="self" type="application/rss+xml" />

		<item>
			<title>Carl Hancock on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-49297</link>
			<pubDate>Mon, 13 Feb 2012 16:13:38 +0000</pubDate>
			<dc:creator>Carl Hancock</dc:creator>
			<guid isPermaLink="false">49297@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Currently there is no merge tag option to only output the filename of an uploaded file.  The way the file upload field works is the full path URL to the file that is uploaded is what is stored as the value in the database.  We can see about adding this feature in the future as a merge tag option for the File Upload field but it is not currently a feature.&#60;/p&#62;
&#60;p&#62;As for the ability to control the filename, it would be added as an available hook.  It would not be added to the form editor UI itself.  It would only exist as a hook for developers to use to implement a customization.  This is because it's a feature that the majority of users would not use or need so therefore it's better suited as a hook rather than adding it to the UI.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chineseand on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-49295</link>
			<pubDate>Mon, 13 Feb 2012 16:09:53 +0000</pubDate>
			<dc:creator>Chineseand</dc:creator>
			<guid isPermaLink="false">49295@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Carl,&#60;br /&#62;
Yeah, sorry for the confusion. I was referring to the as-yet non-existent functionality to give a title to the filename.. &#60;/p&#62;
&#60;p&#62;Is there a function within the system already that would allow writing the filename, and not the url? Something like this:&#60;br /&#62;
&#60;code&#62;&#38;lt;div id=&#38;quot;uploadedfile3&#38;quot;&#38;gt;&#38;lt;a href=&#38;quot;{File 3:11:full:url}&#38;quot; target=&#38;quot;_blank&#38;quot;&#38;gt;{File 3:11:filename}&#38;lt;/a&#38;gt;&#38;lt;/div&#38;gt;&#60;/code&#62;&#60;br /&#62;
Currently, I use this:&#60;br /&#62;
&#60;code&#62;&#38;lt;div id=&#38;quot;uploadedfile3&#38;quot;&#38;gt;&#38;lt;a href=&#38;quot;{File 3:11:full:url}&#38;quot; target=&#38;quot;_blank&#38;quot;&#38;gt;{File 3:11}&#38;lt;/a&#38;gt;&#38;lt;/div&#38;gt;&#60;/code&#62;&#60;br /&#62;
but it is outputting the full url to the attachment instead of the filename only. &#60;/p&#62;
&#60;p&#62;Thanks again for your help. These support forums have been great.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Carl Hancock on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-49271</link>
			<pubDate>Mon, 13 Feb 2012 14:17:08 +0000</pubDate>
			<dc:creator>Carl Hancock</dc:creator>
			<guid isPermaLink="false">49271@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;@Chineseand We haven't yet added a hook that can be used to rename the file that is uploaded.  Currently it is only possible to rename the directory.  We do handle storing the filename properly if it has special characters by using built in WordPress filename sanitization functionality.&#60;/p&#62;
&#60;p&#62;As for your question regarding an admin option, I'm not exactly sure what you are referring to as far as making the &#34;pretty filename&#34; field mandatory.  I don't know what &#34;pretty filename&#34; you are talking about.  Can you clarify?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chineseand on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-48390</link>
			<pubDate>Sun, 05 Feb 2012 14:56:44 +0000</pubDate>
			<dc:creator>Chineseand</dc:creator>
			<guid isPermaLink="false">48390@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Any update on this? Could there be the admin option to make the &#34;pretty filename&#34; field mandatory?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Carl Hancock on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-42624</link>
			<pubDate>Wed, 30 Nov 2011 19:02:03 +0000</pubDate>
			<dc:creator>Carl Hancock</dc:creator>
			<guid isPermaLink="false">42624@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;While there is a hook to customize the upload path, and the file permission, there currently is not a hook to customize the uploaded file name.  I will discuss this with our lead developer tomorrow and see if this is something we can get added to the 1.6.2 release which is getting ready to be pushed live.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ecafe on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-42594</link>
			<pubDate>Wed, 30 Nov 2011 17:20:01 +0000</pubDate>
			<dc:creator>ecafe</dc:creator>
			<guid isPermaLink="false">42594@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Has the ability to rename uploaded files been implemented yet?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-34162</link>
			<pubDate>Thu, 01 Sep 2011 11:33:51 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">34162@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Check to see if the value is empty before inserting it.  Which line of code does the insert, and what value will be empty when you don't want to create an empty custom field?  I'm not sure which line in the code above does that.  If you can point to the code, we can help you figure out how to avoid inserting an empty value.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>charger15 on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-34161</link>
			<pubDate>Thu, 01 Sep 2011 11:29:42 +0000</pubDate>
			<dc:creator>charger15</dc:creator>
			<guid isPermaLink="false">34161@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;just found the solution. i added the following line of code after the $wpdb-&#38;gt;update&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;update_post_meta($entry[&#38;quot;post_id&#38;quot;], &#38;#39;file_upload&#38;#39;, $new_file_url, $original_file_url);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;however i still don't know how to avoid empty fields to be inserted as custom fields with empty value.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>charger15 on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-33681</link>
			<pubDate>Sat, 27 Aug 2011 11:21:52 +0000</pubDate>
			<dc:creator>charger15</dc:creator>
			<guid isPermaLink="false">33681@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;@Alex Cancado: &#60;/p&#62;
&#60;p&#62;I'm using your function above (the one with multiple file upload fields) to rename the uploaded files – works like a charm. The files get renamed and the DB fields are updated.&#60;br /&#62;
I now made a function that takes the custom field values of the file upload fields and adds them as attachments so that I can see them in the media library. It looks like that:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_post_submission&#38;quot;, &#38;quot;usr_custom_fields_to_attachment&#38;quot;, 10, 2);
function usr_custom_fields_to_attachment($entry, $form){

  //ignore requests from forms other than ID 1
  if($form[&#38;#39;id&#38;#39;] != 1)
    return;

  //getting post
  $post = get_post($entry[&#38;#39;post_id&#38;#39;]);

  // add uploaded files as post attachment
  $file_values = get_post_custom_values(&#38;#39;file_upload&#38;#39;, $post-&#38;gt;ID);
  foreach($file_values as $value) {
    if($value != &#38;#39;&#38;#39;){
      //update post meta with absolute path (needed for wp_insert_attachment)
      $abspath = $_SERVER[&#38;#39;DOCUMENT_ROOT&#38;#39;] . wp_make_link_relative($value);
      update_post_meta($post-&#38;gt;ID, &#38;#39;file_upload&#38;#39;, $abspath, $value);
      //check file type
      $wp_filetype = wp_check_filetype(basename($abspath), null );
      //create attachment object
      $attachment = array(
        &#38;#39;post_mime_type&#38;#39; =&#38;gt; $wp_filetype[&#38;#39;type&#38;#39;],
        &#38;#39;post_title&#38;#39; =&#38;gt; preg_replace(&#38;#39;/\.[^.]+$/&#38;#39;, &#38;#39;&#38;#39;, basename($abspath)),
        &#38;#39;post_content&#38;#39; =&#38;gt; &#38;#39;&#38;#39;,
        &#38;#39;post_status&#38;#39; =&#38;gt; &#38;#39;inherit&#38;#39;
      );
      //insert attachment and process attached file
      $attach_id = wp_insert_attachment($attachment, $abspath, $post-&#38;gt;ID);
      require_once(ABSPATH . &#38;#39;wp-admin/includes/image.php&#38;#39;);
      $attach_data = wp_generate_attachment_metadata($attach_id, $abspath);
      wp_update_attachment_metadata($attach_id, $attach_data);
    }
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;My problem now is: When I use your function, the custom fields won't get updated (only the DB), so in there is still the link with the old file name. My function then processes the outdated custom fields and of course can't find the image. I'm unable to see how I can update the metadata inside your function or to get the updated fields directly out of the DB and use them inside my function. Any help?&#60;/p&#62;
&#60;p&#62;I set up the fields in your function like that (The last added parameter in usr_rename_file is only used for the new filename):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_post_submission&#38;quot;, &#38;quot;usr_rename_fileuploads&#38;quot;, 10, 2);
function usr_rename_fileuploads($entry, $form){

    //ignore requests from forms other than ID 1
    if($form[&#38;quot;id&#38;quot;] != 1)
        return;

    usr_rename_file($entry, $form, 28, 1); //renaming file upload field 1 id=28
    usr_rename_file($entry, $form, 29, 2); //renaming file upload field 2 id=29
    usr_rename_file($entry, $form, 30, 3); //renaming file upload field 3 id=30
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Another little question on top: If the user doesn't upload a second or third file, Gravity Form anyway creates the custom field but without value. How can I avoid this behavior?&#60;/p&#62;
&#60;p&#62;Thanks!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>alpersari on "Renaming uploaded files before saving"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/renaming-uploaded-files-before-saving#post-15413</link>
			<pubDate>Tue, 04 Jan 2011 15:56:51 +0000</pubDate>
			<dc:creator>alpersari</dc:creator>
			<guid isPermaLink="false">15413@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi,&#60;br /&#62;
I've tried to rename while uploading by using first function you submitted. But it doesn't work for me. I'm using Xampp for windows.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
