PHP code example of maymeow / file-upload

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

    

maymeow / file-upload example snippets


'Storage' => [
    'defaultStorageType' => env('STORAGE_DEFAULT_STORAGE_TYPE', 'local'),
    'local' => [
        'managerClass' => LocalStorageManager::class,
        'storagePath' => env('STORAGE_LOCAL_STORAGE_PATH', ROOT . DS . 'storage' . DS),
    ],
    'bunny' => [
        'managerClass' => BunnyStorageManager::class,
        'cdnDomain' => env('BUNNY_STORAGE_CDN_DOMAIN', ''), // your cnd url
        'region' => env('BUNNY_STORAGE_REGION', ''), // region, empty is DE
        'baseHostName' => 'storage.bunnycdn.com', // base host name not changeable
        'storageZone' => env('BUNNY_STORAGE_ZONE', ''), // your storage zone name
        'storageZonePath' => env('BUNNY_STORAGE_ZONE_PATH', ''), // folder in zono
        'accessKey' => env('BUNNY_STORAGE_ACCESS_KEY', ''), // API key for write access
    ]
]

$this->addPlugin('FileUpload'); // in your Application.php bootstrap function

return [
    // .. your other plugins
    'FileUpload' => [],
];

$config = Configure::read('Storage.local'); // or Storage.bunny

// or by setting it with .env STORAGE_DEFAULT_STORAGE_TYPE
$storageType = Configure::read('Storage.defaultStorageType');
$config = Configure::read('Storage.' . $storageType); 

$this->loadComponent('FileUpload.Upload', $config);
$this->loadComponent('FileUpload.Download', $config);

$file = $this->Upload->getFile($this);
// do something with file

// store your file name in database
$file->getFileName(); // sanitized file name - with removed restricted characters in the name

$file = $this->Download->getFile($resource->name);
// do something with file

$file->get('storagePath'); // local: /patht/to/sorage or bunny: https://cdn.your.tld/path/to/folder/
// combine it with filename from your database go download it
ini
BUNNY_STORAGE_ACCESS_KEY=
BUNNY_STORAGE_CDN_DOMAIN=
BUNNY_STORAGE_ZONE=