sandip / cake3.x_file_upload
Installs: 655
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 1
Type:cakephp-plugin
Requires
- php: >=5.5.9
- cakephp/cakephp: >=3.1.0 <4.0
This package is not auto-updated.
Last update: 2025-01-15 11:13:16 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.0.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 sandip/cake3.x_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']); }