2012-04-13 74 views
1

我在我的项目中使用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')); 

这可以让你转移单击文件浏览器中选择多个文件,然后把文件放到一个数组以保存...但是,该字段格式不由媒体插件处理。另外,就我所知,无法在保存时添加模型,组等字段。

那么,有没有人知道我可以使用单片模型处理多媒体插件的多文件上传?我接受所有建议。

在此先感谢。

回答

0

请问这个CakePHP 2.x插件 - AjaxMultiUpload - 是否适合您?我认为这正是你需要的。