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

Comments

Crell’s picture

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?

webchick’s picture

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.

lewmich’s picture

YES. This feature would be really worthy. Sollution presented by webchick in #2 looks great.

doc2@drupalfr.org’s picture

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 like if ($type->image) { } else { upload_path code }. I tried with isset as well, but, see, I'm a newbie and couldn't make it work.

Big thanks in advance! Greetings,
Arsène

davidwhthomas’s picture

StatusFileSize
new7.75 KB

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

Crell’s picture

David, can you roll a proper patch so people can review it? Thanks.

davidwhthomas’s picture

StatusFileSize
new3.46 KB

Here's the patch generated from :

diff -up uploadpath_original.module uploadpath.module > uploadpath.patch

See attached :-)

doc2@drupalfr.org’s picture

I'll try this soon and let you know! Thanx in advance David!

doc2@drupalfr.org’s picture

Status: Active » Needs review

Hey, big thank you! Looks and works great!

Therefore I made an archive of the patched module, containing the patch infos within the module and readme file.

http://arsene.richard.free.fr/ged/uploadpath_20071108-patched.zip

Sorry, no garanties, code needs review! I don't know yet how to make official releases (if ever I were granted to). Therefore the module's version has not been changed.

doc2@drupalfr.org’s picture

JUST IN CASE: Patch suggestions for per-nodetype uploadpath redirection without default:
http://drupal.org/node/192752

davidwhthomas’s picture

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

doc2@drupalfr.org’s picture

Support request on uploadpath_20071108_patched module:

I have a "files/videos" folder for my video nodetype. I'd like uploadpath redirections to subfolders according to taxonomy terms.

EX.:
If I want a video:
- tagged with a taxonomy term "AAA" to be uploaded in a files/video/AAA subfolder

and a video:
- tagged with a taxonomy term "BBB" to be uploaded in a files/video/BBB subfolder

... can I use the token patterns to do so, and how?

Thanx for any hint or explanation!

Arsène

davidwhthomas’s picture

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

SergeyK’s picture

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?

davidwhthomas’s picture

The latest patch is available in this related thread:

http://drupal.org/node/192752#comment-657282

DT

davidwhthomas’s picture

Status: Needs review » Closed (fixed)

committed