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.

Gform upload path and not adding to media gallery

  1. I am running a small store that sells printed products. i use woocommerce to add gravity forms to each product and i have it working as needed.

    My main question is this:

    Currently using an image upload form for a product, customer enters details and uploads an attached file, this file then ends up in the following directory;

    "/wp-content/uploads/gravity_forms/10-687a16a21ea392337fbf6916c2442fb8/2013/01/Abstract-2560x1600.jpg"

    is there a way to change directory to;

    "/artwork/2013/01/Abstract-2560x1600.jpg"

    so new directory and removed the random characters.

    any help appreciated.

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  2. Have you already tried using the gform_upload_path filter?

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

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  3. no haven't seen that,

    do i just add that to the forms_model.php without removing anything?

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  4. David Peralty

    Actually, it goes in your theme's Functions.php file. All my best!

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  5. ok i added the following to my theme functions.php file;

    //Changing Upload PATH
    	add_filter("gform_upload_path", "change_upload_path", 10, 2);
    	function change_upload_path($path_info, $form_id){
       		$path_info["path"] = "../../artwork/";
       		$path_info["url"] = "http://www.superwideprints.co.uk/artwork/";
       return $path_info;
    }

    in the cart where it preview the image uploaded i get the following link to the image;

    http://www.superwideprints.co.uk/cart/FAILED%20(Upload%20folder%20could%20not%20be%20created.)

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  6. On line 4, I would use a complete path rather than a relative path, just to make sure it's going where you want.

    Does the folder exist in that location already? What are the permissions of the folder and the parent folder? The error there is that the upload folder could not be created. Please create the folder in the proper location with the proper permissions and see if you can upload a small file.

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  7. yes complete path worked great.

    although it doesn't sort them into month and day anymore.

    can this be added?

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  8. or even better adding the "form name" as a sub folder as well as date and day?

    Posted 11 years ago on Thursday January 17, 2013 | Permalink
  9. That hook has the form ID available to it as $form_id. So, you could do something like this:

    [php]
    add_filter("gform_upload_path", "change_upload_path", 10, 2);
    function change_upload_path($path_info, $form_id){
        $path_info["path"] = "/fullpath/var/www/website/artwork/" . $form_id . "/";
        $path_info["url"] = "http://www.superwideprints.co.uk/artwork/". $form_id . "/";
        return $path_info;
    }

    That would put them into the correct folder with the form ID at least. They were never in month and day. WordPress uploads are always in Year and Month. Gravity Forms adds the special folder based on the form ID and a random string.

    I'm not sure if Gravity Forms will create a non-existent root folder when it first goes to store an upload. If not, you'd have to figure out how to ensure the folder exists first. If you do not have a lot of forms, you can create all the upload folders one time before you use the form, so the upload folder is there.

    Posted 11 years ago on Friday January 25, 2013 | Permalink
  10. Will that scripting allow you to dynamically create a folder based on user name?

    Posted 11 years ago on Tuesday January 29, 2013 | Permalink
  11. David Peralty

    That hook wouldn't have access to the user name, so you would have to write another script to global the username and pass it to this hook for use as part of the path name creation, but that is beyond what we can do here in support.

    Posted 11 years ago on Wednesday January 30, 2013 | Permalink