public function changePicture()
    {
        $id = $this->Auth->user('id');

        if ($this->request->getData('file')) {
            //Deletes any picture that already exists
            foreach (((new Folder(USER_PICTURES))->find($id . '\..+')) as $filename) {
                @unlink(USER_PICTURES . $filename);
            }

            $filename = sprintf('%s.%s', $id, pathinfo($this->request->getData('file')['tmp_name'], PATHINFO_EXTENSION));

            $uploaded = $this->Uploader->set($this->request->getData('file'))
                ->mimetype('image')
                ->save(USER_PICTURES, $filename);

            if (!$uploaded) {
                return $this->setUploadError($this->Uploader->getError());
            }

            //Updates the authentication data and clears similar thumbnails
            $this->Auth->setUser(array_merge($this->Auth->user(), ['picture' => $uploaded]));
            (new ThumbManager)->clear($uploaded);
        }
    }
public function changePicture()
    {
        $id = $this->Auth->user('id');

        if ($this->request->getData('file')) {
            //Deletes any picture that already exists
            foreach (((new Folder(USER_PICTURES))->find($id . '\..+')) as $filename) {
                @unlink(USER_PICTURES . $filename);
            }

            $filename = sprintf('%s.%s', $id, pathinfo($this->request->getData('file')['tmp_name'], PATHINFO_EXTENSION));

            $uploaded = $this->Uploader->set($this->request->getData('file'))
                ->mimetype('image')
                ->save(USER_PICTURES, $filename);

            if (!$uploaded) {
                return $this->setUploadError($this->Uploader->getError());
            }

            //Updates the authentication data and clears similar thumbnails
            $this->Auth->setUser(array_merge($this->Auth->user(), ['picture' => $uploaded]));
            (new ThumbManager)->clear($uploaded);
        }
    }
public function changePicture ( ) { $ id = $ this -> Auth -> user ( 'id' ) ; if ( $ this -> request -> getData ( 'file' ) ) { //Deletes any picture that already exists foreach ( ( ( new Folder ( USER_PICTURES ) ) -> find ( $ id . '\..+' ) ) as $ filename ) { @ unlink ( USER_PICTURES . $ filename ) ; } $ filename = sprintf ( '%s.%s' , $ id , pathinfo ( $ this -> request -> getData ( 'file' ) [ 'tmp_name' ] , PATHINFO_EXTENSION ) ) ; $ uploaded = $ this -> Uploader -> set ( $ this -> request -> getData ( 'file' ) ) -> mimetype ( 'image' ) -> save ( USER_PICTURES , $ filename ) ; if ( ! $ uploaded ) { return $ this -> setUploadError ( $ this -> Uploader -> getError ( ) ) ; } //Updates the authentication data and clears similar thumbnails $ this -> Auth -> setUser ( array_merge ( $ this -> Auth -> user ( ) , [ 'picture' => $ uploaded ] ) ) ; ( new ThumbManager ) -> clear ( $ uploaded ) ; } }
Changes the user's picture
@return \Cake\Network\Response|null|void
@uses MeCms\Controller\AppController::setUploadError()
@uses MeTools\Controller\Component\UploaderComponent
Changes the user s picture