首页 > 解决方案 > Cakephp 3图像上传如何从模型中保存文件名

问题描述

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

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

$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

标签: cakephpcakephp-3.x

解决方案


推荐阅读