krolow/Attach — pull request #10 by boundaryfunctions (2012-05-15 01:26:07+00:00)
Title: Dynamic names for subfolder structure

Hi,

first things first: after looking at the published plugins for upload handling in Cake 2.x, I think the codebase of this one is the nicest because it uses Cake's features in a very decent way. In my opinion, this should grow to be the 'standard' plugin for this thing with Cake 2.

I just recognized, that this still lacks some features and I hope I can help out a little here. I just added a simple option for a dynamic folder structure. To use it, you can put it in your model like this:

public $actsAs = array(
'Attach.Upload' => array(
'image' => array(
'dir' => 'webroot{DS}content{DS}{model}{DS}{type}{DS}{index}'
),
),
);

`{model}` is replaced by the name of the calling model, i.e. `Foobar`
`{type}` is replaced by the media type, i.e. `image`
`{index}` is replaced by the id of the current entry, i.e. `42`

So in the example above, images might be saved to `app/webroot/content/Foobar/image/42/`.

Still missing is the same thing for filenames (including the original name as a placeholder) and storing the path in the DB (currently I'm just doing it in the view, because I needed it for my current project only in one place either way). Please let me know, if you like the idea, and I will add the missing stuff when I have time for it.