how do I upload images (Media) to specific folders inside the default directory? I will have thousands of pictures and would like to have an organized structure of folders.

Thanks a lot.

  • 2
    Is it D7 or D6 ? You can configure a Directory per content type, go to Edit Content Type and check image related settings. – GoodSp33d Dec 17 '12 at 17:09
  • Hi, it's D7. hmmm... Each image will be part of the same content type ("photo") so that will not solve my issue. (I have a reference for a content type "gallery" that shows all the "photos" of that gallery). If I could choose a separate folder for each "gallery" would be nice... do you know anything? Thanks for you help – Daniel Dec 17 '12 at 17:15

You can use File (Field) Paths module. It allows you to automatically sort and rename your uploaded files using token based replacement patterns to maintain a nice clean filesystem.

You can use value of any node field as folder name where files will be uploaded. Or you can create new field for this purpose.

  • Thanks Eugene. This sounds good. I could have a text field in my content type like "upload images to" and then use this value as the path to store the file. – Daniel Dec 18 '12 at 11:07
  • @Daniel Exactly – Eugene Fidelin Dec 18 '12 at 11:13

If you wanted a programmatic solution, you could use the setting array when creating field instance:

'settings' => array(
        'file_directory' => 'YOUR_DIRECTORY_HERE',

For example:

 // Create the instance.
    $instance = array(
      'field_name' => $field_name,
      'entity_type' => 'node',
      'bundle' => 'article',
      'label' => 'Article Image',
      'description' => 'An image for the article.',
      'required' => TRUE,
      'settings' => array(
        'file_extensions' => 'png jpg jpeg',
        'file_directory' => 'myModule/news', //your wanted attribute
        'max_filesize' => '20 MB',
        'alt_field' => 1,
        'title_field' => 1,
        'max_resolution' => '300x200',
        'min_resolution' => '200x125',
        'default_image' => 0,

If you just want to upload image in sub directory. their is configuration for drupal image field . Path is your_example_domain.com/admin/structure/types/manage/your_content_type/fields/field_image. you can set the file directory by using token and like static name "your_subdir_name". hope this help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.