I use meioupload to upload images in cakePHP, i use a table called 'attachment' to save the uploaded image's information, this is the structure of my attachment table:
CREATE TABLE IF NOT EXISTS `attachments` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`class` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`foreign_id` bigint(20) unsigned NOT NULL,
`filename` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`dir` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`mimetype` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
`filesize` bigint(20) DEFAULT NULL,
`height` bigint(20) DEFAULT NULL,
`width` bigint(20) DEFAULT NULL,
`description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
And i currently have another 2 tables connected with this through the class field (table name) and foreign_id. Now my question is, how can i save the uploaded image to a different folder for each model?
For example: i would like to save my post's image into 'post' folder and to save my profile image into 'profile' folder
UPDATE: in my attachment model
public $actsAs = array(
'MeioUpload' => array(
'filename' => array(
'dir' => 'post', #i set the default folder as 'post' at the moment
'create_directory' => true,
'allowed_mime' => array(
'image/jpeg',
'image/pjpeg',
'image/png'
),
'allowed_ext' => array(
'.jpg',
'.jpeg',
'.png'
),
'thumbsizes' => array(
'large' => array(
'width' => 500,
'height' => 500
),
'small' => array(
'width' => 100,
'height' => 100
)
)
)
)
);
UPDATE #2 : let say that i currently have 3 tables, "attachment" "post" and "profile", the one that actAs meioupload is "attachment", every time i upload an image through "post" or "profile", i will save the image information into "attachment", foreign_id and class fields in "attachment" is the one connecting "attachment" to "post" and "profile".
UPDATE #3 : i followed Dunhamzzz suggestion on using the behavior on the fly, and come up with this solution, and it works.
$this->Attachment->Behaviors->attach(
'MeioUpload', array(
'filename' => array(
'dir' => 'avatars'
)
));
Thanks