Summary: Describe how to set Drupal up so that when you upload a file with the default Drupal upload module, the file goes to the directory of your choosing, and NOT to the default single flat directory structure.

Modules you need: Upload (core), Upload Paths, Token, Taxonomy (core)

My example: City Website, with tons of departments. ie. Finance, MIS, CityCouncil, Engineering, etc...

What file structure did I end up with?
sites/default/files/Finance
sites/default/files/MIS
sites/default/files/CityCouncil (you get the idea)

My Taxonomy Structure: (Set these to be required -- This way, you won't have to worry about anything ending up in your default files dir)
Departments
-> Finance
-> MIS
-> CityCouncil

Content Type info:
admin/content/type [manage fields]
Here, I simply put the Taxonomy entry right above the File upload on all the nodes, so that way these two things where next to each other:

[Department -> select]
Upload a file.

Since the above is required, it's going to make sure that the file gets to the right place.

Finally, Upload Path (module)
This is where the real magic is. Go here: admin/settings/uploadpath

Default pattern for the file path prefix: [term]
Make sure you save your settings. This is the part that tells drupal's upload module "Yo dude, you want the file you upload, to go with the Taxonomy item you selected. In my above example, if I wanted a file to go to the CityCouncil dir, then I'd select CityCouncil from the Department list. Then my file would get pushed to:
sites/default/files/CityCouncil

et voila!

I hope this helps. I also wanted to document this in case I needed to do this again some time in the future.

Please let me know if this is redundant, or if I've forgotten any steps.

Cheers,
Trae

Comments

rwilson0429’s picture

For Drupal 7, you can use File (Field) Paths module to achieve this functionality.

ReggieW