I am using the Media Plugin (http://www.ohloh.net/p/cakephp-media).
I wanna define custom folder for all the uplaods. i am a little confused where it has to be done.
This is the folder structure i want to achieve
webroot/media/image/original (for the original file storage)
webroot/media/image/large (for the large image filter)
webroot/media/image/medium (for the medium image filter)
webroot/media/image/small (for the small image filter)
also i want to use a random name that i want to generate using the following sript.
//UUID generator
function _imgName() {
return time() . substr(md5(microtime()), 0, 12);
}
Firstly, having used this plugin, I would recommend considering the default directory structure to keep your app simpler. You don’t want to edit the plugin directly as it will make upgrading more painful…
However, the Media plugin configuration file is located at
/app/plugins/media/config/core.phpand contains some constants that you can override application-wide by defining them in/app/config/bootstrap.phpfirst. To achieve a format somewhat similar to what you want, you could define the following variables:(Note: you can also set the above paths on a per-model basis by passing the correct configuration options when adding the behavior to your models.)
You can also redefine the names of the image filters being used to get a step closer to your goal. You need to do this in
/app/config/bootstrap.phpagain, but after you have loaded the Media plugin configuration:If you read the documentation for the
Media.TransferBehavior::transferTo()method, you will see you can customize the latter part of the path (ie.img/slug.ext) by reimplementing this method in your model (eg.MyModel::transferTo()). Something like this would get you even closer:While not exactly what you were looking for (
/large/image/vs/image/large/), this is about as far as you can go without reimplementing larger portions of the plugin. This is because the path is treated as two parts (eg./media/large/andimage/129916998392a3570a1828.ext) that get appended together later. You can see the append operation happening in theMedia.TransferBehavior::_prepare()method and in theMedia.GeneratorBehavior::make()method. You would need to either extend the plugin and duplicate those methods (with alterations) in your application code, or hack those two lines directly to get the desired output!