我用meioupload上傳在CakePHP的圖片,我使用了一個名爲「附件」保存上傳的圖片的信息表,這是我的附件表的結構:CakePHP的meioupload,上傳圖像到不同的文件夾,每個模型
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;
而我目前有另外2個表通過類字段(表名)和foreign_id與此連接。現在我的問題是,如何將上傳的圖像保存到每個模型的不同文件夾?
例如:我想救我的帖子的形象進入「後」文件夾和我的個人資料圖片保存到「配置文件」文件夾
UPDATE:在我的附件模型
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
)
)
)
)
);
更新#2:讓我說,我目前有3個表,「附件」「帖子」和「配置文件」,actAs meioupload是「附件」,每次我通過「發佈」或「配置文件」 ,我會將圖像信息保存到「附件」中,foreign_id和class字段i n「附件」是將「附件」連接到「帖子」和「配置文件」的附件。
更新#3:我遵循Dunhamzzz有關使用行爲的建議,並提出了這個解決方案,它的工作原理。
$this->Attachment->Behaviors->attach(
'MeioUpload', array(
'filename' => array(
'dir' => 'avatars'
)
));
感謝
請從模型發表您的$ ACTAS代碼。 – alexdd55 2011-06-10 09:16:29
@alex我已更新我的問題 – littlechad 2011-06-10 09:34:24