【问题标题】:Why cakephp image uploader plugin isnot working?为什么 cakephp 图片上传插件不起作用?
【发布时间】:2014-04-07 15:40:34
【问题描述】:

我正在尝试在 ajax 调用期间上传图片。为此,我使用了一个插件来创建缩略图。但它也没有插入任何数据和缩略图。

我正在提供我的插件链接以及控制器代码和模型:

https://github.com/josegonzalez/cakephp-upload

$club_id = $this->request->data['Photo']['club_id'];
$id = $this->Auth->user();
$this->request->data['Photo']['user_id'] = $id["id"];
$this->request->data['Photo']['club_id'] = $club_id;
$this->request->data['Photo']['photo_type'] = "club";
$this->request->data['Photo']['profile_picture'] = "no";
$this->Photo->save($this->request->data);

和型号代码:

public $actsAs = array(
     'Upload.Upload' => array(
          'picture' => array(
           'path' => '{ROOT}webroot{DS}img{DS}{model}{DS}{field}{DS}',
             'fields' => array(
               'dir' => 'picture_dir'
                 ),                
                 'thumbnailSizes' => array(
                    'thumb' => '100x100'
                  ), 'thumbnailMethod' => 'php'
          )
     )
  );

我的视图文件是:

$this->Form->create($id, array('type' => 'file', "id" => "multiform"));
$this->Form->input('picture', array('type' => 'file'));
$this->Form->button('Upload', array('type' => 'submit', "id" => "club_upload"));
$this->Form->end();

它不是在数据库中创建缩略图和数据。我坚持下去,任何想法都会帮助我。

【问题讨论】:

  • 遇到任何错误(错误/调试日志)?上传没有ajax的图片,有什么帮助吗?因为通过 ajax 上传图片需要的代码与标准 POST 请求有点不同:)
  • 不,我没有收到任何错误!

标签: cakephp


【解决方案1】:

这应该可行:

public $actsAs = array(
    'Upload.Upload' => array(
        'path' => '{ROOT}webroot{DS}img{DS}{model}{DS}{field}{DS}',
        'fields' => array(
            'dir' => 'picture_dir'
        ),
        'thumbnailSizes' => array(
            'thumb' => '100x100'
        ),
        'thumbnailMethod' => 'php',
        'deleteOnUpdate'  => true
    )
);

编辑:

在视图文件中:

$this->Form->create('Photo', array('type' => 'file', "id" => "multiform"));

id 作为表单名称传递是个坏主意。

现在您可以像这样访问您的数据:

 $this->request->data['Photo']['picture']

您可能已经为club_id 字段添加表单。

【讨论】:

  • 它不工作,它没有将任何数据保存到数据库中,也没有创建任何文件夹
  • @CrazyMan 你能用表单添加查看文件吗?
  • @CrazyMan 有什么错误吗?检查app/tmp/logs/error.log
猜你喜欢
  • 1970-01-01
  • 2012-05-01
  • 2016-06-08
  • 2018-12-05
  • 1970-01-01
  • 1970-01-01
  • 2012-08-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多