PHP code example of dala00 / cakephp-simple-upload

1. Go to this page and download the library: Download dala00/cakephp-simple-upload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dala00 / cakephp-simple-upload example snippets


Plugin::load('Dala00/Upload');

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}'
				],
			],
		]);
	}
}

// In Controller
public $helpers = ['Dala00/Upload.Upload'];

(In Templates)
<img src="<?= $this->Upload->url($entity, $fieldName) 

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