【问题标题】:CakePHP (2.1) Media Plugin - Multi File UploadCakePHP (2.1) 媒体插件 - 多文件上传
【发布时间】:2012-06-27 05:07:01
【问题描述】:

我在我的项目中使用 cakephp 媒体插件,使用整体样式附件表,即所有附件都放在一个表中,其中外键、模型、组等与文件详细信息一起保存。所以我的模型看起来像:

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');

但我认为您会同意必须单击浏览每个文件有点麻烦。我可以看到允许多个文件上传的最简单方法是使用 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'));

这允许您在文件浏览器中移动单击以选择多个文件,然后将文件放入数组中保存...但是,媒体插件不处理此字段格式。此外,据我所知,无法在保存中添加模型、组等字段。

那么,有人知道我如何使用单片模型通过媒体插件处理多文件上传吗?我愿意接受所有建议。

提前致谢。

【问题讨论】:

    标签: file cakephp plugins upload media


    【解决方案1】:

    这个 CakePHP 2.x 插件 - AjaxMultiUpload - 对你有用吗?我认为这正是您需要的。

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      相关资源
      最近更新 更多