bikash / cake_file_upload
Upload files and images, create thumb for images in CakePHP
Package info
github.com/bikashc003/cake_file_upload
Type:cakephp-plugin
pkg:composer/bikash/cake_file_upload
v1.0
2019-11-19 18:04 UTC
Requires
- php: >=5.5.9
- cakephp/cakephp: >=3.6.0 <4.0
This package is not auto-updated.
Last update: 2026-03-20 00:04:49 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
- 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 ]); } }
- 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']); }