1 | <?php |
||
17 | class UploadAction extends Action |
||
18 | { |
||
19 | /** |
||
20 | * @var string $modelName The name of model |
||
21 | */ |
||
22 | public $modelName; |
||
23 | /** |
||
24 | * @var string $attribute |
||
25 | */ |
||
26 | public $attribute; |
||
27 | /** |
||
28 | * @var string $inputName The name of the file input field |
||
29 | */ |
||
30 | public $inputName; |
||
31 | /** |
||
32 | * @var string $type The type of the file (`image` or `file`) |
||
33 | */ |
||
34 | public $type = 'image'; |
||
35 | /** |
||
36 | * @var string $multiple Multiple files |
||
37 | */ |
||
38 | public $multiple = false; |
||
39 | /** |
||
40 | * @var string $template Path to template for multiple files |
||
41 | */ |
||
42 | public $template; |
||
43 | /** |
||
44 | * @var string $resultFieldId The name for field of the response, in which the id to the file |
||
45 | */ |
||
46 | public $resultFieldId = 'id'; |
||
47 | /** |
||
48 | * @var string $resultFieldPath The name for field of the response, in which the path to the file |
||
49 | */ |
||
50 | public $resultFieldPath = 'path'; |
||
51 | /** |
||
52 | * @var int $ownerId The id of the owner |
||
53 | */ |
||
54 | public $ownerId = -1; |
||
55 | /** |
||
56 | * @var bool $temporary The file is temporary |
||
57 | */ |
||
58 | public $temporary = true; |
||
59 | /** |
||
60 | * @var ActiveRecord $model |
||
61 | */ |
||
62 | private $model; |
||
63 | /** |
||
64 | * @see http://www.yiiframework.com/doc-2.0/guide-tutorial-core-validators.html |
||
65 | * @var array $rules |
||
66 | */ |
||
67 | private $rules; |
||
68 | |||
69 | 33 | public function init() |
|
83 | |||
84 | 32 | public function run() |
|
103 | |||
104 | /** |
||
105 | * Upload |
||
106 | * |
||
107 | * @param yii\web\UploadedFile $file |
||
108 | * @return string JSON |
||
109 | */ |
||
110 | 30 | private function upload($file) |
|
136 | |||
137 | /** |
||
138 | * Create a file |
||
139 | * |
||
140 | * @param yii\web\UploadedFile $file |
||
141 | * @return rkit\filemanager\models\File |
||
142 | */ |
||
143 | 30 | private function createFile($file) |
|
156 | |||
157 | /** |
||
158 | * Apply preset for file |
||
159 | * |
||
160 | * @param string $path |
||
161 | * @param array $presetAfterUpload |
||
162 | * @return void |
||
163 | */ |
||
164 | 21 | private function applyPreset($path, $presetAfterUpload) |
|
170 | |||
171 | /** |
||
172 | * JSON Response |
||
173 | * |
||
174 | * @param mixed $data |
||
175 | * @return string JSON Only for yii\web\Application, for console app returns `mixed` |
||
176 | */ |
||
177 | 32 | private function response($data) |
|
186 | } |
||
187 |