PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Change upload path for specific file_upload field 2

  1. Hey guys,

    I would have replied to the previous thread, but it was closed...

    I'm trying to hijack the form POST to change the file upload path of one field. Just before submission, I can get the path to change properly, but I'm assuming after it posts, the upload path is hijacked again by the form.

    Here's what I have so far:

    add_action('gform_post_data_1', 'ebooks_review_book', 10, 2);
    	function ebooks_review_book($form) {
    
    		$img    = $form['images'][0]['url'];
    		$img    = explode('/', $img);
    		$img    = $img[sizeof($img)-1];
    
    		$form['images'][0]['url']                    = content_url() . '/uploads/books/' . $img;
    
    		echo "<pre>";
    		print_r( $form );
    		echo "</pre>";
    
    		exit;
    		//return $form;
    	}

    Is there a hook I can use to make this work? One that runs after change_upload_path, but before the file is actually moved?

    Thanks,
    jacob

    Posted 11 years ago on Wednesday September 28, 2011 | Permalink
  2. No love?

    Posted 11 years ago on Monday October 3, 2011 | Permalink
  3. Currently the upload path can only be changed site wide or form wide, the hook doesn't currently support per field. The hook is documented here:

    http://www.gravityhelp.com/documentation/page/Gform_upload_path

    I'll check with our lead developer if this can be done on a field by field basis.

    Posted 11 years ago on Monday October 3, 2011 | Permalink
  4. Thanks Carl,

    What I'm trying to do is change the path for a specific field after the form is submitted but before the form is posted. Just not sure why my code above wouldn't work.

    Is there a hook I can use to change the $form data after the change_upload_path but before POST?

    Thanks,
    Jacob

    Posted 11 years ago on Monday October 3, 2011 | Permalink
  5. The problem is this functionality happens when the form is posted. The file upload is handled server side. You can't change the path as part of the form post because Gravity Forms handles the file upload and moves the file based on it's own settings, not what is posted. The only way to change the path is to use the hook I referenced above and currently it only works per form, it can't be used on a field by field basis.

    Posted 11 years ago on Monday October 3, 2011 | Permalink
  6. I don't see any update for this hook or any other options in GF Help Forum.

    Is it still impossible to change gform_upload_path based off of the Field ID?

    Posted 9 years ago on Wednesday February 27, 2013 | Permalink
  7. David Peralty

    That's correct. We have not changed how file uploads are processed, and as such, its upload location can't be set through field choices.

    Posted 9 years ago on Wednesday February 27, 2013 | Permalink