私はcakePHPで画像をアップロードするためにmeiouploadを使用します。アップロードされた画像の情報を保存するために「添付ファイル」という表を使用します。これは添付ファイルテーブルの構造です: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;
私は現在、これとクラスフィールド(テーブル名)とforeign_idを介して別の2つのテーブルを接続しています。今私の質問は、どのようにアップロードされたイメージを各モデルの別のフォルダに保存できますか?例えば
:i「はポスト」フォルダの中に私のポストの画像を保存すると「プロファイル」フォルダの中に私のプロフィール画像を保存したい
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
)
)
)
)
);
UPDATE#2:私は現在、3つのテーブル "attachment" "post"と "profile"を持っているとしましょう。meiouploadとして動作するものは "post"または "profile"私は、画像情報を「添付ファイル」、foreign_id、およびクラスフィールドに保存します。 n "attachment"は、 "post"と "profile"に "attachment"を接続するものです。
UPDATE#3:私はDunhamzzzの提案にしたがって、その場で行動を使用し、この解決策を思いついた。
$this->Attachment->Behaviors->attach(
'MeioUpload', array(
'filename' => array(
'dir' => 'avatars'
)
));
答えはあなたのMeioUpload、特に「DIR」オプションであるおかげ
PLSは、お使いのモデルから$ actAsコードをポスト変更することができ、キー「DIR」があります。 – alexdd55
@alex私の質問が更新されました – littlechad