PHP code example of fm-labs / cakephp-upload

1. Go to this page and download the library: Download fm-labs/cakephp-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/ */

    

fm-labs / cakephp-upload example snippets


// Example Controller

class UploadController extends \Cake\Controller\Controller
{
    public function upload()
    {
        // create Uploader instance
        $uploader = new \Upload\Uploader([]);
        // alternatively the uploader config can be loaded from a config file
        // (copy example config from PLUGIN/config/upload.sample.php to app/config/upload.php)
        //\Cake\Core\Configure::load('upload');
        //$uploader = new \Upload\Uploader('default');
    
        // process the uploaded data
        $uploader->upload($this->getRequest()->getData('uploadfile'));
        
        // the result is a list of uploaded files
        // [[
        //  'name' => '/path/to/file',
        //  'size' => (int) 1234,
        //  'mime_type' => 'text/plain'
        //  'error' => 0
        // ], [...]]
        $result = $uploader->getResult();
    }

}

// Example upload form using CakePHP FormHelper
<?= $this->Form->create(null);