Allow setting directory per-node type
webchick - June 15, 2007 - 16:35
| Project: | Upload path |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
For example, we might have a "Document" node type that we'd like to go into files/documents/YYYY-MM/filename.pdf and a "Photo" node type that should go into files/images/category/picture.jpg

#1
Hm. I suppose that would likely involve moving the confirm form to the node type config page. Of course, how then would you just set a single global rule? Or per-node type with a fallback to global if nothing is specified?
#2
Global fallback seems like the best option. yeah.
Something like:
Global upload path:
[ textfield ]
[ node type #1 (collapsed fieldset: no value exists yet) ]
[ node type #2 (expanded fieldset: value exists ]
[ textfield ]
etc.
#3
YES. This feature would be really worthy. Sollution presented by webchick in #2 looks great.
#4
I need this badly too, especially to avoid conflicts with the image and video modules.
Else, what code to put in the module to avoid certain content type?
Just below
If (isset($node->files)) ..., I tried to put something likeif ($type->image) { } else {upload_path code}. I tried withissetas well, but, see, I'm a newbie and couldn't make it work.Big thanks in advance! Greetings,
Arsène
#5
I added this feature to my install of uploadpath.
You can set the upload path for each content type.
If a path is not set, the default uploadpath path will be used.
The files are attached.
To install, you can just overwrite the existing files with the new ones and visit the file upload paths config / settings page
#6
David, can you roll a proper patch so people can review it? Thanks.
#7
Here's the patch generated from :
diff -up uploadpath_original.module uploadpath.module > uploadpath.patchSee attached :-)
#8
I'll try this soon and let you know! Thanx in advance David!
#9
Hey, big thank you! Looks and works great!
#10
JUST IN CASE: Patch suggestions for per-nodetype uploadpath redirection without default:
http://drupal.org/node/192752
#11
Thanks, glad to hear it works for you too.
I'm using it myself and it's working perfectly :-)
There's a few notes in the comments that could be taken out of a released version (lines 101 - 103 in .module file)
and I'm considering adding the bugfix ( http://drupal.org/node/153737 ) as an optional config setting that can be toggled from admin, in case people want to switch it off, but it works for me and fixes the bug I had with the token module and dates and allows setting paths for each node type.
Thanks to the original dev as this is a very useful drupal extension!
regards,
DT
#12
Support request on uploadpath_20071108_patched module:
Thanx for any hint or explanation!
Arsène
#13
Re: Support request on uploadpath_20071108_patched module
In that case, you would create the pattern:
video/[term]for the "Video" node / content-type.
you could also set it as :
[type]/[term] or [type]/[cat]as the default pattern and [type] will be replaced by the 'video' content type name.
[type] selects the node type
[term] selects "Name of top taxonomy term"
or perhaps
[catpath] "Same as [cat], but including nodes supercategories separated by /"The available tokens are listed in the 'replacement patterns' fieldset in admin > site configuration > file upload paths
It's useful to add date tokens to order your folders by date.
e.g if a pattern like :
[type]/[yyyy]/[mm]orders files automatically by creating folder by date.
regards,
DT
#14
David, thank you for the great job! Your module works fine on my almost clear D5 installation and solves token module date() error message (http://drupal.org/node/153737). But now I am thinking of another feature. Is it possible to integrate "clean" node title produced by Pathauto module into Uploadpath path rendering? Imagine, you have a story titled "Lorem, ipsum". For this node Pathauto (when tuned properly) will generate a path like www.example.com/lorem-ipsum (notice, comma is eliminated, space is replaced by hyphen separator char). As for Uploadpath, used with [title] pattern, it will generate path like www.example.com/lorem,_ipsum. What am I looking for is a common way for naming stories' aliases and paths of images attached to that stories, so that image.jpg will sit in www.example.com/lorem-ipsum, not lorem,_ipsum. Is it possible to implement a hook or fetch processed title data from Pathauto for Uploadpath?
#15
The latest patch is available in this related thread:
http://drupal.org/node/192752#comment-657282
DT
#16
committed