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.

How do I have user generated image uploads to specific folder in media library?

  1. mavellino
    Member

    I have created a form for user generated uploads of images with posts that are embedded in the post body. The posts from this form upload to a blog category. When the images upload to my media library, they are just in the general medial library folder. I would like to have these images in a seperate folder in my media library from my logo and other admin images. How can I do that?

    Posted 13 years ago on Monday August 22, 2011 | Permalink
  2. How about the gform_upload_path to change the location where the uploads are stored?

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

    Posted 13 years ago on Monday August 22, 2011 | Permalink
  3. mavellino
    Member

    Thanks. A few more questions though since I am a newbie to all of this. I need to upload them to an id#. Do I need to make the url path with a folder for that id# in my media library? And please specifically tell me on what line # I should insert the code in the link above....
    Thank you.

    Posted 13 years ago on Monday August 22, 2011 | Permalink
  4. What do to mean "to an id"? They need to be stored in folders by some sort of unique ID, or form ID or post ID? What is the ID? Or will the ID be part of the file name?

    Because it's PHP code, you will insert the gform_upload_path code into functions.php.
    http://www.gravityhelp.com/documentation/page/Where_Do_I_Put_This_Code%3F

    Posted 13 years ago on Monday August 22, 2011 | Permalink
  5. mavellino
    Member

    Yes, I am talking about the post category id that the form content creates. So if I understand this correctly, I need to edit the theme functions.php file with the code you mentioned? Do I need to create the folder in the media library first for the images? Please give me step by step instructions on how to do this.
    Thanks :)

    Posted 13 years ago on Tuesday August 23, 2011 | Permalink
  6. 1. Yes, you would add this to the functions.php file in your current theme.

    2. No you do not need to create the folder in the media library. The folder doesn't even have to be in the media library.

    Regarding the category id, that is a more complex customization. By default, Gravity Forms stores the uploads in folders like this: wp-content/uploads/gravity_forms/$form_ID/YEAR/MM/upload.jpg

    Can you explain more about what you want to do any why they need to be separated into folders by post category? Maybe that will help someone come up with a solution for you.

    Posted 13 years ago on Thursday August 25, 2011 | Permalink
  7. mavellino
    Member

    If I understand correctly, the path will stay with the form I created, therefore I do not have to associate the images with the post category.
    So I insert this code exactly as you see it here into my functions.php file?

    1 <?php
    2 add_filter("gform_upload_path", "upload_path", 10, 2);
    3 ?>

    Please let me know if I have to change anything. What does the 10,2 mean?
    Thanks.

    Posted 13 years ago on Wednesday September 7, 2011 | Permalink
  8. The path will contain the form ID in it, so you can keep uploads organized by form. But that is not related at all to categories.

    There's more to the code that just that one line though. Please take a look at this page of the documentation and refer to the last code block.

    Also, be sure you do not paste in the line numbers as you did in your previous post.

    Finally, the 10, 2 means run with a priority of 10 (default) and 2 are the number of arguments the function will accept. You can read more about this at wordpress.org.

    Posted 13 years ago on Wednesday September 7, 2011 | Permalink
  9. mavellino
    Member

    Thanks!

    Posted 13 years ago on Wednesday September 7, 2011 | Permalink
  10. mavellino
    Member

    Hi Chris, I spoke too soon!
    Do you mean this code block?
    <?php
    2 add_filter("gform_upload_path", "change_upload_path", 20, 2);
    3 function change_upload_path($path_info, $form_id){
    4 $path_info["path"] = "/new/path/";
    5 $path_info["url"] = "http://new_url.com/images/";
    6 return $path_info;
    7 }
    8 ?>
    If yes, I am still confused as to where I input my folder name and do I set the folder up first and where? I know to add my ford id # after the path. I know not to copy the line numbers in. Sorry, I am a newbie, but these directions are a little vague and I don't know where to type my information in the code.
    Thanks.

    Posted 13 years ago on Wednesday September 7, 2011 | Permalink
  11. mavellino
    Member

    Also, my form does not display the date dropdown box. It is cut off. Any reason why?

    Posted 13 years ago on Wednesday September 7, 2011 | Permalink
  12. @mavellino, we are going to ignore the date dropdown question here. Start a new topic for that with a link to your form, and in what browser you see the problem.

    Regarding the previous post:

    • Yes that code block. You need all that in a <?php section of your theme's functions.php
    • Line 4 will be the full path on the server to your folder.
    • Line 5 will be the URL where you can access that folder. The end part will be the same
    • Yes, you need to create the folder first. You are telling Gravity Forms where the folder is, but it will not create it.

    Please ask if you need additional help with this.

    Posted 13 years ago on Wednesday September 7, 2011 | Permalink