dala00/cakephp-simple-upload

Upload handle plugin for CakePHP

Installs: 323

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:cakephp-plugin

1.0.5 2017-01-27 12:44 UTC

This package is not auto-updated.

Last update: 2024-09-24 20:17:13 UTC


README

Software License Build Status Coverage Status

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) ?>

Licence

MIT