dala00 / cakephp-simple-upload
Upload handle plugin for CakePHP
Installs: 328
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=5.4.16
- cakephp/cakephp: ~3.0
Requires (Dev)
This package is not auto-updated.
Last update: 2025-01-28 21:53:58 UTC
README
Description
- Handle file post to save and upload automatically.
- UploadHelper can output URL and img tag on template.
- Methods for confirm page are available.
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require dala00/cakephp-simple-upload
And load plugin on bootstrap.php.
Plugin::load('Dala00/Upload');
Usage
Load UploadBehavior with options.
class SomeTable extends Table { public function initialize(array $config) { $this->addBehavior('Dala00/Upload.Upload', [ 'fields' => [ 'photo' => [ 'path' => 'webroot{DS}files{DS}{model}{DS}{primaryKey}{DS}{field}{DS}' ], ], ]); } }
UploadHelper
You can output URL or img tag with UploadHelper.
// In Controller public $helpers = ['Dala00/Upload.Upload'];
(In Templates) <img src="<?= $this->Upload->url($entity, $fieldName) ?>"> or <?= $this->Upload->image($entity, $fieldName) ?> <?= $this->Upload->image($entity, $fieldName, $options) ?>
Using confirm page
If you want show confirm page before saving post, next method saves files as cache.
// Call in action when confirm page will be shown $this->SomeTable->uploadTmpFile($entity);
// Output hidden tag with UploadHelper on templates <?= $this->Upload->hidden($entity, $fieldName) ?>