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.

Custom Image Upload Path

  1. mavellino
    Member

    Hi

    I have few forms which are using image upload feature of GRAVITY FORMS, I want to define a custom path for each form instead that it uploads to my media library.

    How do I do that, and if there is a code snippet or filter that does it, where to I put that filter ???

    Posted 13 years ago on Thursday September 22, 2011 | Permalink
  2. sascha
    Member

    Hi there,
    I do not seem to get the upload path filter to work. I use this code:

    ´add_filter("gform_upload_path", "change_upload_path", 10, 2);
    function change_upload_path($path_info, $form_id){
    $path_info["path"] = "/html/landwire/submissions/";
    $path_info["url"] = "http://www.landwire.de/submissions/";
    return $path_info;

    I looked at your links and cannot make anymore sense out of it. Sorry. Maybe you could show me another example or two? Or tell me where I am going wrong...
    "landwire.de" is the domian name
    "landwire" the directory on the server that the site is installed in. landwire lies in a folder "html" on the server. There seem to be no other folders above "html".

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink
  3. sascha
    Member

    FYI:
    I have created a directory on the server and gave it 777. I do not get any error messages either - the form submits ok. If I take the filter out files get uploaded properly to the standard upload folder.

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink
  4. sascha
    Member

    Ok, Im getting this error message when I view the form entries:
    FAILED (Upload folder could not be created.)
    So maybe my path and url are wrong. Cannot think what they could be though. How do I find out?

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink
  5. sascha
    Member

    Fixed it! Maybe it helps someone: instructions to find your absolute path:

    Here is what you can use for the php script to find the absolute path:

    <?php
    $path = getcwd();
    echo "This Is Your Absolute Path: ";
    echo $path;
    ?>

    Save the above file as findpath.php. It is important that you use '.php' (without the quotes) in the file name as you are making a php script file.

    You now need to upload this file to your web server. Put this file in the public_html folder of your web server. This will be the root directory of your domain. If you have sub-domains inside that root directory with additional Joomla! installs you will need to put it into the appropriate folder. For the most part, if you only have one domain being served by your web hosting service, it will go in the public_html folder.

    To invoke this script and find the absolute path for your Joomla! installation all you need to do is type in your browser window:

    http://www.yourdomainname.com/findpath.php

    Thanks!

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink
  6. sascha
    Member

    Other question:
    How do I get the year and months folders back when I use the filter? At the moment it just stores the files in "submissions".
    And sorry for all the postings before, but hopefully this script will help many users. Maybe you could put in somewhere on the filter site. Might save you a lot of questions...
    Thanks,
    Sascha

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink
  7. I'm not sure what you are asking. The filter overrides things and places the files in the folder you specify. If the filter in place, that is where the files are going to go.

    Gravity Forms uploads using the File Upload field aren't stored in year/month folders. They are stored by default in the gravity_forms folder and then in dynamically created folders with a unique folder name associated with the entry and form.

    The Media Library stores items using your Media settings. Gravity Forms does not, it's not part of the Media Library.

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink
  8. sascha
    Member

    Hi Carl,
    that's strange. My standard path looks like this:
    /html/landwire/wp-content/uploads/gravity_forms/4-8bce87129732fcf2d740bba2abb15260/2011/11
    I have the latest GF 1.6.1 and WP 3.2.1 installed. Should the "form" folder look like this with all those numbers (4-8bce....)? As you see the 2011/11 gets created by GF. I checked that on a clean install of GF and WP - no other plug-in installed. As soon as you use the "gform_upload_path" filter the 2011/11/ is not created anymore. In the meantime I figured out how to get the 2011/11 back. I have one problem though:
    how can I get the form title in this function, where I create the folders based on role and username:

    add_filter("gform_upload_path", "change_upload_path", 10, 2);
    function change_upload_path($path_info, $form_id){
    	$currentuserrole = get_current_user_role();
          	get_currentuserinfo();
    	$currentusername = $current_user->user_login;
    
    	$path_info["path"] = "/home/www/web116/html/landwire/gf_submissions/$currentuserrole/$currentusername/";
    	$path_info["url"] = "http://www.landwire.de/gf_submissions/$currentuserrole/$currentusername/";
    return $path_info;
    }

    I tried:

    $form = self::get_form($form_id);
            $title = $form->title;

    But that will not work.
    I also need to retrieve the Post Title (when I am using post fields). Any ideas how I can achieve this within my "change_upload_path" function above?

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink