我正在尝试在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);
AND MODEL CODE:
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();
它没有在数据库中创建缩略图和数据。我坚持下去,任何想法都会帮助我。
答案 0 :(得分:0)
这应该有效:
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
字段添加表单。