我想在我的cakephp 3.0应用程序中上传图像.但我收到错误消息:
Notice (8): Undefined index: Images [APP/Controller/ImagesController.php, line 55]
Run Code Online (Sandbox Code Playgroud)
在cakePHP 3.0中是否已经有一些上传文件(一次多个文件)的例子?因为我只能找到cakePHP 2.x的例子!
我想我需要在ImagesTable.php中添加自定义验证方法?但我无法让它发挥作用.
ImagesTable
public function initialize(array $config) {
$validator
->requirePresence('image_path', 'create')
->notEmpty('image_path')
->add('processImageUpload', 'custom', [
'rule' => 'processImageUpload'
])
}
public function processImageUpload($check = array()) {
if(!is_uploaded_file($check['image_path']['tmp_name'])){
return FALSE;
}
if (!move_uploaded_file($check['image_path']['tmp_name'], WWW_ROOT . 'img' . DS . 'images' . DS . $check['image_path']['name'])){
return FALSE;
}
$this->data[$this->alias]['image_path'] = 'images' . DS . $check['image_path']['name'];
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)
ImagesController
public function add()
{
$image = $this->Images->newEntity();
if ($this->request->is('post')) {
$image …Run Code Online (Sandbox Code Playgroud)