Cakephp 3图片上传如何保存模型中的文件名

时间:2019-09-24 17:01:51

标签: cakephp cakephp-3.x

我正在尝试在模型中保存文件名。

我已经实现了使用以下代码在模型中上传文件的代码

$validator 
      ->add('image',[
                    'mimeType' => [
                        'rule'    => ['mimeType',['image/jpg', 'image/png', 'image/jpeg']],
                        'message' => 'Please upload only jpg and png.',
                        'last' => true,
                    ],
                    'processImageUpload'=>[
                        'rule'     => 'processImageUpload',
                        'provider' => 'table',
                        'message'  => 'Unable to process cover image upload.',
                    ],
      ]);

      return $validator;

在processImageUpload中,我想保存文件名。但是名称不能保存

public function processImageUpload($check = array()) {

           // upload file code here working fine

            $this->image = 'uploads/'. $check['name']; //not working
            return TRUE;
}

如何通过模型方法将图像名称保存在图像字段中?

版本:3.8.4

0 个答案:

没有答案