Please help with this one - I've been trying to figure out if this is possible for quite some time.

I'm about to make a website for a local magazine and I'm really really interested to find out how I could organize uploaded images?
to me it doesn't make sense that every time I upload an image it always goes to the same directory. Give the magazine a couple of issues and one ends up with a huge folder of images.

Is there a way to do this? please help :)

Comments

ingacosta’s picture

Version: 5.x-1.2-rc1 » 5.x-2.0-rc6

I have the same issue, and I would like using a diferent folder for each user

jpetso’s picture

Status: Active » Fixed

Different directories for different users is possible right now, just install the Token module and use token support for the field's target directory. All user properties can be used for that purpose.

Sorting by issue (or by node, for that matter) is more difficult... like, impossible at the moment, as there is no support for node tokens (yet?). Those are being discussed in this feature request: #221104: Node tokens. Please follow that issue for any updates on that matter.

omnyx’s picture

thanks for the quick reply!

I'd ideally like to have users specify their path on upload. So let's say this week, all images go to 080307 (year, month, friday) folder in files/images/. Can token module do something like that?

Going back to users uploading to their own directories - what do I do to enable that? I don't see a configuration tab for token module, only for pathauto...

thanks

ingacosta’s picture

same problem. ¿how can I do that? I need a cck_token module? or I use [subdirectoryprefix] token to the path?

jpetso’s picture

So, you make use of tokens (whatever kind of them) by editing the desired content type -> Manage fields -> [configure the filefield] -> enter the desired file path. If the Token module is enabled, you'll find user and global tokens below the "File path" field, and you can use all of those in the file path. In order to store files separately for each user, you'd specify e.g. "[uid]" as file path (and uploaded files will then appear in "files/378" for example).

Now, having something like 080307 is more difficult because there's no global token for such fine-grained date descriptions, at least not provided by the Token module by default. The ideal way would probably be a date CCK field in that content type (which enables to specify the issue date and extract the fine-grained date parts) but I'm not aware of how the date information could be accessed for the filefield file path.

So, the most straightforward solution would probably be a small custom module which provides this "080307" global token. Relatively easy, but you need to know Token and PHP nonetheless. I can't think of a better solution right now.

ingacosta’s picture

Thanks a lot! Now I can have a folder for each user!

I think that the token [site-date] could be useful for Omnyx.

Using [site-date] in the path, it creates (using today date for example):
One folder Fri,03
One subfolder 07

It stores images in path: "files/Fri,03/07"

You can also choose store at "files/photos/Fri,03/07" filling "/photos/[site-date]" in the path field.

omnyx’s picture

thanks to both of you for being helpful but I just don't see that field.
When I go to modify->field I see

Image Path:

Optional subdirectory within the "files" directory where images will be stored. Do not include trailing slash

And that's all. I don't see what tokens are available. Jpesto, what are the "global tokens" you spoke about?

ingacosta - i don't think there is a [site-date] token. I only see [date-in-tz] token. Is that what you were referring to?

jpetso’s picture

omnyx: hm... I guess you're still using 5.x-1.2 then, as indicated in the original issue description. As far as I remember, Token support is only present in imagefield 5.x-2.x (which is arguably a bit buggy at the moment).

omnyx’s picture

how about this - every month (or week) I go to the 'manage fields' setting and change the default directory. Would that work? It seems it should as it would only affect newly created nodes and not the old ones. Jpetso - do you see a reason why this would be bad? If not, I think that's almost perfect solution for me.

one more thing (if you happen to know this one I will build you a statue :) so I can add an additional cck text field to be the caption of the image, but how do I make sure that field is always displayed right below my image. It might have to do with grouping in css but I'm dying to find that out :)

ingacosta’s picture

Yes, there is a token [site-date], it's a global token. I'm using image_field 2.0 RC-6, token 5.x-1.10 and CCK 5.x-1.6

It seems you can't see the tokens because you are using 5.x-1.2 version of imagefield. Try using 2.0 rc-6 version with the patch.

I don't remember very well but I think you can change the image-patch without problems.

jpetso’s picture

@omnyx:
Yes, changing the default directory would work, it only applies to new files. Not the most elegant or maintenance-free solution, but very well functional - if you don't mind doing the change every month, I don't see any problems with this.

As for the caption text... I guess you could do that with per-content-type templates, but I'd probably override the theme_imagefield_image() function (by copying it to your template.php file and renaming to phptemplate_imagefield_image()). In your new copy, you could then just modify the line

    return '<img src="'. check_url($url) .'" alt="'.
        check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' />';

and display the "title" attribute not only as such but also as caption:

    return '<div class="imagefield"><img src="'. check_url($url) .'" alt="'.
        check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' /><br/>
        <span class="imagefield-caption">'. check_plain($title) .'</span></div>';

Of course, "Title" needs to be displayed for the specific imagefield, if it's not enabled already then you'll find that setting in the field configuration. When migrating to Drupal 6, you'll have to adapt that code/snippet, but that's probably necessary for the content-type-themed approach as well. Untested, but should pretty much work, I guess. Now, the statue.

omnyx’s picture

jpetso - thank for the quick reply!
However I still can't get this to work - the display of my node is still unchanged.
The function is phptemplate_imagefield_image(...) (I also tried putting function phptemplate_my own image filed name_image() )
I put it on the bottom of template.php file..

any ideas?
thanks!

jpetso’s picture

hm... maybe it's the cache. try emptying the {cache}, {cache_content} and {cache_page} tables. I don't really see why the page wouldn't at least change *somehow* otherwise.

omnyx’s picture

@jpetso - the code you've given does make a change but only when I edit the node. You know that when one edits the node there is the little line with 'browse' next to it. When I find the image and click upload then the small version of the image is displayed to the left (even though we are still editing the node). That display of image is changed with the code and, unfortunately, not the one when the whole node is submitted (or in preview mode).

I tried emptying the imagecache but that didn't help. Also I don't know how much of a cache problem it can be since no caption for the newly made nodes is displayed...

jpetso’s picture

Hm, yeah, if newly created nodes don't have the caption then it must be something different than caching. No idea, though... and I don't really have the motivation to do remote debugging on this. Perhaps the theme developer module can provide a bit more guidance for you on this, I'm outta here. Good luck!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

hemant-gupta’s picture

Title: different folder for uploading? » Is it possible in different folder for each nodes ?

Hi,

I'm using token for nodes similar to user upload but not success!

Is it possible to upload images in separate folder for each nodes using token or by any other way? Please help if so...