sandip/cake3.x_file_upload
Composer 安装命令:
composer require sandip/cake3.x_file_upload
包简介
README 文档
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']); }
统计信息
- 总下载量: 663
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-29