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 of the field that contains the id of the file in the response |
||
45 | */ |
||
46 | public $resultFieldId = 'id'; |
||
47 | /** |
||
48 | * @var string $resultFieldPath The name of the field that contains the path of the file in the response |
||
49 | */ |
||
50 | public $resultFieldPath = 'path'; |
||
51 | /** |
||
52 | * @var bool $temporary The file is temporary |
||
53 | */ |
||
54 | public $temporary = true; |
||
55 | /** |
||
56 | * @var ActiveRecord $model |
||
57 | */ |
||
58 | private $model; |
||
59 | /** |
||
60 | * @see http://www.yiiframework.com/doc-2.0/guide-tutorial-core-validators.html |
||
61 | * @var array $rules |
||
62 | */ |
||
63 | private $rules; |
||
64 | |||
65 | 27 | public function init() |
|
79 | |||
80 | 26 | public function run() |
|
99 | |||
100 | /** |
||
101 | * Upload |
||
102 | * |
||
103 | * @param UploadedFile $file |
||
104 | * @return string JSON |
||
105 | */ |
||
106 | 24 | private function upload($file) |
|
138 | |||
139 | /** |
||
140 | * Apply preset for file |
||
141 | * |
||
142 | * @param string $path |
||
143 | * @param array $presetAfterUpload |
||
144 | * @return void |
||
145 | */ |
||
146 | 21 | private function applyPreset($path, $presetAfterUpload) |
|
152 | |||
153 | /** |
||
154 | * JSON Response |
||
155 | * |
||
156 | * @param mixed $data |
||
157 | * @return string JSON Only for yii\web\Application, for console app returns `mixed` |
||
158 | */ |
||
159 | 26 | private function response($data) |
|
168 | } |
||
169 |