bikash/cake_file_upload

Upload files and images, create thumb for images in CakePHP

Installs: 26

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:cakephp-plugin

v1.0 2019-11-19 18:04 UTC

This package is not auto-updated.

Last update: 2025-08-07 20:50:47 UTC


README

It can be used to upload a file, create thumbnails, remove file, create a file from image base64 data

Requirements

The master branch has the following requirements:

  • CakePHP 3.6.0 or greater.
  • PHP 5.4.16 or greater.

Installation

  • Install the plugin with Composer from your CakePHP Project's ROOT directory (where the composer.json file is located)
composer require bikash/cake_file_upload
Plugin::load('FileUpload');

How to use

  1. Load plugin in controller's initialise function
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
        ]);
    }

}
  1. call a function to upload image
 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']);
    }