18
18
19
19
## Installation
20
20
21
+ 1 . Installing using Composer
21
22
```
22
23
composer require rkit/filemanager-yii2
23
24
```
25
+
26
+ 2 . Run migrations
27
+ ```
28
+ php yii migrate --migrationPath=@vendor/rkit/filemanager-yii2/src/migrations/ --interactive=0
29
+ ```
30
+
24
31
## Configuration
25
32
26
33
Add the following in your config, in section ` components `
@@ -44,7 +51,9 @@ Add the following in your config, in section `components`
44
51
]
45
52
```
46
53
47
- ## Basic usage
54
+ ## Usage
55
+
56
+ ### Basic usage
48
57
49
58
1 . ** Controller**
50
59
@@ -96,6 +105,9 @@ Add the following in your config, in section `components`
96
105
// save file id in this table
97
106
// 'saveFileId' => true,
98
107
108
+ // protected a file
109
+ // 'protected' => true,
110
+
99
111
// @see http://www.yiiframework.com/doc-2.0/guide-tutorial-core-validators.html
100
112
'rules' => [
101
113
'imageSize' => ['minWidth' => 300, 'minHeight' => 300],
@@ -137,15 +149,9 @@ Add the following in your config, in section `components`
137
149
138
150
3 . ** View**
139
151
140
- Any widget for ajax upload.
141
- Use ` $model->getFileRulesDescription($attribute) ` for get a description of rules
142
- ```
143
- Min. size of image: 300x300px
144
- File types: JPG, JPEG, PNG
145
- Max. file size: 1.049 MB
146
- ```
152
+ Any widget for ajax upload
147
153
148
- ## Thumbnails
154
+ ### Thumbnails
149
155
150
156
- Apply a preset and return public path
151
157
@@ -165,7 +171,7 @@ Add the following in your config, in section `components`
165
171
$model->thumb('preview', '200x200', null, true);
166
172
```
167
173
168
- ## Gallery
174
+ ### Gallery
169
175
170
176
1 . ** Controller**
171
177
@@ -199,7 +205,7 @@ Add the following in your config, in section `components`
199
205
</li >
200
206
```
201
207
202
- ## Save after upload
208
+ ### Save after upload
203
209
204
210
For example this could be a need for wysiwyg editor,
205
211
when you need to immediately save the file after upload and assign the owner.
@@ -221,16 +227,52 @@ public function actions()
221
227
}
222
228
```
223
229
224
- ## Manually create a file
230
+ ### Manually create a file from path
231
+
232
+ ``` php
233
+ object Yii::$app->fileManager->create('/path/to/file', $ownerId, $model->getFileOwnerType($attribute), true);
234
+ ```
235
+
236
+ ### Manually create a file from URL
225
237
226
- - From path
238
+ ``` php
239
+ object Yii::$app->fileManager->create('http://…/path/to/file', $ownerId, $model->getFileOwnerType($attribute), true);
240
+ ```
227
241
228
- ``` php
229
- Yii::$app->fileManager->create('/path/to/file', $ownerId, $model->getFileOwnerType($attribute), true)
230
- ```
242
+ ### Manually create a ** protected** file from path
231
243
232
- - From URL
244
+ ``` php
245
+ object Yii::$app->fileManager->create('/path/to/file', $ownerId, $model->getFileOwnerType($attribute), true, true);
246
+ ```
233
247
234
- ``` php
235
- Yii::$app->fileManager->create('http://…/path/to/file', $ownerId, $model->getFileOwnerType($attribute), true)
236
- ```
248
+ ### Get files
249
+
250
+ ``` php
251
+ array $model->getFiles($attribute);
252
+ ```
253
+
254
+ ### Сheck whether a file is protected
255
+
256
+ ``` php
257
+ bool $model->isProtected($attribute);
258
+ ```
259
+
260
+ ### Get a description of rules
261
+
262
+ ``` php
263
+ string $model->getFileRulesDescription($attribute)
264
+ ```
265
+
266
+ Output
267
+
268
+ ```
269
+ Min. size of image: 300x300px
270
+ File types: JPG, JPEG, PNG
271
+ Max. file size: 1.049 MB
272
+ ```
273
+
274
+ ### Get real path to file
275
+
276
+ ``` php
277
+ string $model->getFileRealPath($attribute);
278
+ ```
0 commit comments