试图让CakePHP 上传插件工作。文件上传正常,缩略图被创建......等等,但有一些问题:
-“上传”表中的“名称”字段为空
-“上传”表中的“上传”字段为空(文档示例中的“附件”字段)
- 如果我在上传模型中设置的“路径”中使用 {model},它使用“上传”作为模型文件夹 - 它应该放在关联模型的文件夹中,而不是每次都上传模型
//Upload MODEL
public $actsAs = array(
'Upload.Upload' => array(
'photo' => array(
'thumbnailSizes' => array(
'xvga' => '1024x768',
'vga' => '640x480',
'thumb' => '80x80',
),
'thumbnailMethod' => 'php',
'path' => '{ROOT}webroot{DS}uploads{DS}{model}{DS}{field}{DS}',
'maxSize' => '5242880', //5MB
'mimetypes' => array('image/jpeg', 'image/png', 'image/gif', 'image/bmp'),
'extensions' => array('jpg', 'gif', 'png'),
),
)
);
//ArticleData MODEL
public $hasMany = array(
'Upload' => array(
'className' => 'Upload',
'foreignKey' => 'foreign_key',
'conditions' => array(
'Upload.model' => 'ArticleData',
),
),
);
//CONTROLLER
public function admin_upload() {
if(!empty($this->request->data)) {
$this->loadModel('Upload');
debug($this->request->data);
if($this->Upload->save($this->request->data)) {
$this->Session->setFlash('SAVED!!!!!!!!');
} else {
$this->Session->setFlash('NOT SAVED!!!!!!!!');
}
}
}
// VIEW
echo $this->Form->create('ArticleData', array('type'=>'file'));
echo $this->Form->input('Upload.model', array('type'=>'hidden', 'value'=>'ArticleData'));
echo $this->Form->input('Upload.foreign_key', array('type'=>'hidden', 'value'=>'4f93676e-347c-4e0c-8e6c-0a3cadcd7f7c'));
echo $this->Form->input('Upload.photo', array('type'=>'file'));
echo $this->Form->end('Submit');