我在我的項目中使用cakephp媒體插件,使用單體樣式附件表,即所有附件都與foreign_key,model,group等一起放入一個表中文件的詳細信息。所以我的模型看起來像:CakePHP(2.1)媒體插件 - 多文件上傳
class ProjectProfile extends AppModel {
var $name = 'ProjectProfile';
var $useDbConfig = 'default';
var $useTable = 'project_profiles';
var $actsAs = array('Media.Transfer', 'Media.Generator');
public $belongsTo = array(
'Project' => array(
'className' => 'Project',
'foreignKey' => 'pjID'
)
);
var $hasMany = array(
'Photo' => array(
'className' => 'Media.Attachment',
'order' => 'Photo.basename, Photo.id',
'foreignKey' => 'foreign_key',
'conditions' => array('Photo.model' => 'ProjectProfile', 'Photo.group' => 'Photo'),
'dependent' => true)
);
然後一個saveAll在控制器保存我的記錄時保存附加的文件。
這一切工作正常,但是我真的希望能夠一次上傳多個文件,通過形式做這裏面的插件不支持:
echo $this->Form->hidden('Photo.0.model', array('value' => 'Photo'));
echo $this->Form->input('Photo.0.file', array('type' => 'file');
echo $this->Form->hidden('Photo.1.model', array('value' => 'Photo'));
echo $this->Form->input('Photo.1.file', array('type' => 'file');
echo $this->Form->hidden('Photo.2.model', array('value' => 'Photo'));
echo $this->Form->input('Photo.2.file', array('type' => 'file');
但我認爲你會同意,點擊瀏覽每個單獨的文件有點麻煩。該simplist方法,我可以看到,以允許多文件上傳是使用HTML5多個文件部分的選項 - http://bakery.cakephp.org/articles/veganista/2012/01/31/html_5_multiple_file_upload_with_cake:
echo $this->Form->input('files.', array('type' => 'file', 'multiple'));
這可以讓你轉移單擊文件瀏覽器中選擇多個文件,然後把文件放到一個數組以保存...但是,該字段格式不由媒體插件處理。另外,就我所知,無法在保存時添加模型,組等字段。
那麼,有沒有人知道我可以使用單片模型處理多媒體插件的多文件上傳?我接受所有建議。
在此先感謝。