You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:warning: This is readme for version 2.x. For 1.x go to [v1.1.2](https://github.com/MayMeow/cakephp-fileupload/tree/v1.1.2) release.
4
+
5
+
### :stop_sign: Breaking changes (read before use)
6
+
7
+
Version 2.x is not compatibile with cakephp lower than 5.x and it is not backward compatibile with previous releases of this plugins.
8
+
9
+
- S3 storage support was removed
10
+
- Bunny CND storage support was added
11
+
- All components and Managers was rewritten.
12
+
3
13
Cakephp plugin to upload files to storage and download them. Currently are supported:
4
14
5
15
- Local storage
@@ -19,149 +29,6 @@ The recommended way to install composer packages is:
19
29
composer require maymeow/file-upload
20
30
```
21
31
22
-
## Usage
23
-
24
-
To load plugin addd to `Application.php`
25
-
26
-
```php
27
-
$this->addPlugin('FileUpload');
28
-
```
29
-
30
-
Next load it in controllers where you want to use it. To use default config
31
-
32
-
```php
33
-
public function initialize(): void
34
-
{
35
-
parent::initialize();
36
-
$this->loadComponent('FileUpload.Upload');
37
-
$this->loadComponent('FileUpload.Dowmload'); // in case you wan to download files
38
-
}
39
-
```
40
-
41
-
## Using local storage
42
-
43
-
Commands above are loaded with default configuration:
44
-
- Using Local filesystem: type is set to `local`
45
-
- Data are stored in `sotrage` folder in root of your application - This folder is not public and cannot be served directly from webserver. You need to use `DownloadComponent` to get files
46
-
- Field name for uploading files is `uploaded_file`
47
-
- Allowed are all file types
48
-
49
-
```php
50
-
public function initialize(): void
51
-
{
52
-
parent::initialize();
53
-
$this->loadComponent('FileUpload.Upload', [
54
-
'fieldName' => 'your_form_file_field',
55
-
'storagePath' => 'path_to_storage',
56
-
'allowedFileTypes' => '*'
57
-
]);
58
-
}
59
-
```
60
-
61
-
For `allowedFileTypes` use `'allowedFileTypes' => '*'` for all file types or `'allowedFileTypes' => ['type1', 'type2']` for your expected file types. If file have not allowed type Component will throw `Cake\Http\Exception\HttpException`.
62
-
63
-
Using local storage (default option) you can use default config but do not forge to change allowed file types and form field nam from which you uploading file to server.
64
-
65
-
## Using S3 storage
66
-
67
-
For S3 storage configuration is pretty same as configuration above, but you have to change type to `s3` instead of `local` which is default as follows
68
-
69
-
```php
70
-
public function initialize(): void
71
-
{
72
-
parent::initialize();
73
-
$this->loadComponent('FileUpload.Upload', [
74
-
'fieldName' => 'your_form_file_field',
75
-
'storagePath' => 'bucket_name',
76
-
'storage_type' => 's3'
77
-
]);
78
-
}
79
-
```
80
-
81
-
:exclamation: Dont forget to change configuration for `DownloadComponent` too if you planing using it.
82
-
83
-
Next add configuration for s3 server to your config file `app_local.php` for example as follows:
84
-
85
-
```php
86
-
'S3' => [
87
-
'version' => 'latest',
88
-
'region' => 'us-east-1',
89
-
'endpoint' => 'http://cake_minio:9000',
90
-
'use_path_style_endpoint' => true,
91
-
'credentials' => [
92
-
'key' => 'minioadmin',
93
-
'secret' => 'minioadmin',
94
-
],
95
-
]
96
-
```
97
-
98
-
Config above is for using minio with my [CakePHP starte kit](https://github.com/MayMeow/cakephp-starter-kit). Change it for your needs.
0 commit comments