Skip to content

Commit 58d993d

Browse files
committed
update readme
1 parent 6e8e801 commit 58d993d

File tree

1 file changed

+85
-7
lines changed

1 file changed

+85
-7
lines changed

README.md

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@
66

77
Version 2.x is not compatibile with cakephp lower than 5.x and it is not backward compatibile with previous releases of this plugins.
88

9-
- S3 storage support was removed
9+
- S3 storage support was removed (will be added in future relases)
1010
- Bunny CND storage support was added
1111
- All components and Managers was rewritten.
1212

13-
Cakephp plugin to upload files to storage and download them. Currently are supported:
14-
15-
- Local storage
16-
- S3 Compatible storage
17-
1813
And supported actions are upload and download.
1914

2015
## Installation
@@ -26,7 +21,90 @@ The recommended way to install composer packages is:
2621
## 🐘 From packagist
2722

2823
```
29-
composer require maymeow/file-upload
24+
composer require maymeow/file-upload "^2.0.0"
25+
```
26+
27+
## Usage
28+
29+
Add configuration somewhere to your config files
30+
31+
```php
32+
'Storage' => [
33+
'defaultStorageType' => env('STORAGE_DEFAULT_STORAGE_TYPE', 'local'),
34+
'local' => [
35+
'managerClass' => LocalStorageManager::class,
36+
'storagePath' => env('STORAGE_LOCAL_STORAGE_PATH', ROOT . DS . 'storage' . DS),
37+
],
38+
'bunny' => [
39+
'managerClass' => BunnyStorageManager::class,
40+
'cdnDomain' => env('BUNNY_STORAGE_CDN_DOMAIN', ''), // your cnd url
41+
'region' => env('BUNNY_STORAGE_REGION', ''), // region, empty is DE
42+
'baseHostName' => 'storage.bunnycdn.com', // base host name not changeable
43+
'storageZone' => env('BUNNY_STORAGE_ZONE', ''), // your storage zone name
44+
'storageZonePath' => env('BUNNY_STORAGE_ZONE_PATH', ''), // folder in zono
45+
'accessKey' => env('BUNNY_STORAGE_ACCESS_KEY', ''), // API key for write access
46+
]
47+
]
48+
```
49+
50+
For bunny cdn minimal configuration is to have folowing keys configured
51+
52+
```ini
53+
BUNNY_STORAGE_ACCESS_KEY=
54+
BUNNY_STORAGE_CDN_DOMAIN=
55+
BUNNY_STORAGE_ZONE=
56+
```
57+
58+
If you need/want nginx to server your static files without PHP set `STORAGE_LOCAL_STORAGE_PATH` location to whe webroot folder.
59+
60+
Load plugin with adding
61+
62+
```php
63+
$this->addPlugin('FileUpload'); // in your Application.php bootstrap function
64+
```
65+
66+
or you can add your plugin with `plugins.php` config file
67+
68+
```php
69+
return [
70+
// .. your other plugins
71+
'FileUpload' => [],
72+
];
73+
```
74+
75+
Loading components
76+
77+
```php
78+
$config = Configure::read('Storage.local'); // or Storage.bunny
79+
80+
// or by setting it with .env STORAGE_DEFAULT_STORAGE_TYPE
81+
$storageType = Configure::read('Storage.defaultStorageType');
82+
$config = Configure::read('Storage.' . $storageType);
83+
84+
$this->loadComponent('FileUpload.Upload', $config);
85+
$this->loadComponent('FileUpload.Download', $config);
86+
```
87+
88+
Uploading files
89+
90+
```php
91+
$file = $this->Upload->getFile($this);
92+
// do something with file
93+
94+
// store your file name in database
95+
$file->getFileName(); // sanitized file name - with removed restricted characters in the name
96+
```
97+
98+
```php
99+
$file = $this->Download->getFile($resource->name);
100+
// do something with file
101+
```
102+
103+
:memo: Note that the function above will read content of file and you then need to use response to push it to the viewer. If you want to do it without using PHP you will need to get URL of file and if you using local storage manager your folder need to be in webrootfolder.
104+
105+
```php
106+
$file->get('storagePath'); // local: /patht/to/sorage or bunny: https://cdn.your.tld/path/to/folder/
107+
// combine it with filename from your database go download it
30108
```
31109

32110

0 commit comments

Comments
 (0)