It is very easy to create dynamic Media Sources based on resource ID using Bruno's MIGx-provided 'migxResourceMediaPath' snippet. The base path and URL for your Media Source looks like this:
[[migxResourceMediaPath? &pathTpl=`assets/images/{id}/`]]
This will allow a path of 'assets/images/42/' where the images will be associated with resource #42. Originally, it was developed for use with creating MIGx-based galleries. But it can be used for all sorts of interesting things, like giving editors their own image directories.
You can add an optional &createFolder=`1` property to have the snippet create the resource's folder if it doesn't exist.
This has evolved over time to allowing quite a number of resource-oriented placeholders besides the {id}.
I've added a new variation to this theme, 'migxUsernameMediaPath'. You can use it to create a Media Source that will use a folder for each user.
[[migxUsernameMediaPath? &pathTpl=`assets/images/{username}/`]]
The code modification is simple, but I created a duplicate snippet so that it won't get overwritten if you upgrade MIGx.
Around line 99, just add this:
if ($user = $modx->user) {
$path = str_replace('{username}', $modx->user->get('username'), $path);
}
[ed. note: Bruno17 last edited this post 12 years, 1 month ago.]