PHP code example of bikash / cake_file_upload

1. Go to this page and download the library: Download bikash/cake_file_upload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bikash / cake_file_upload example snippets


Plugin::load('FileUpload');

namespace App\Controller;

use Cake\Event\Event;

/**
 * My Users Controller 
 */
class UsersController extends AppController {

        public function initialize(){
        parent::initialize();
        $this->loadComponent('FileUpload.FileUpload',[
            'defaultThumb'=>[
                'small'=>[30,30],
                'medium' => [90,90 ]
            ],
            'uploadDir' =>WWW_ROOT.'uploads'.DS.'profile_pic'.DS,
            'maintainAspectRation'=>true
        ]);
    }

}

 public function add()
    {
        $user = $this->Users->newEntity();
        if ($this->request->is('post')) {
            $this->request->data['profile_pic'] = $this->FileUpload->doFileUpload($this->request->data['profile_pic']);
            $user = $this->Users->patchEntity($user, $this->request->data);
            if ($this->Users->save($user)) {
                $this->Flash->success(__('The user has been saved.'));
                return $this->redirect(['controller' => 'Users','action' => 'index']);
            } else {
                $this->Flash->error(__('The user could not be saved. Please, try again.'));
            }
        }
        $this->set(compact('user'));
        $this->set('_serialize', ['user']);
    }