cake非法字符串偏移量'name' [APP\Controller\PostsController.php,第 18 行]



我是 cakephp 和 php 的新手,我试图在上传文件后将文件保存在文件夹中。

public function add() {
    if ($this->request->is ( 'post' )) {
        $filename = "app/webroot/img/uploads/" . $this->data ['Post'] ['Image'] ['name'];
        if ((move_uploaded_file ( $this->data ['Post'] ['Image'] ['tmp_name'], $filename ))) {
            $this->Mathang->create ();
            if ($this->Post->save ( $this->request->data )) {
                $this->Session->setFlash ( __ ( 'save images successful.' ) );
                redirect()          
                $this->redirect ( '/posts/upload' );
            }
        } else {
            $this->Session->setFlash ( __ ( 'not save images.' ) );
        }
    }
}
     if ($this->request->is('post') ) {          
     $filename=$this->request->data('Post.image');
    $filename = "app/webroot/img/uploads/".$_FILES[$filename]['name'];
    $tempname=$this->request->data('Post.image');
    if((move_uploaded_file($_FILES[$tempname']['tmp_name'],$filename)){
            if ($this->Post->save($this->request->data)) {
        $this->Session->setFlash(__('save images successful.'));
        redirect()
         $this->redirect('/posts/upload');
    }}else{
    $this->Session->setFlash(__('not save images.'));}
}

最新更新