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 | 28 | public function init() |
|
68 | |||
69 | 27 | public function run() |
|
89 | |||
90 | /** |
||
91 | * Upload |
||
92 | * |
||
93 | * @param UploadedFile $file |
||
94 | * @return string JSON |
||
95 | */ |
||
96 | 25 | private function upload($file) |
|
126 | |||
127 | /** |
||
128 | * Apply preset for file |
||
129 | * |
||
130 | * @param string $path |
||
131 | * @param array $presetAfterUpload |
||
132 | * @return void |
||
133 | */ |
||
134 | 22 | private function applyPreset($path, $presetAfterUpload) |
|
140 | |||
141 | /** |
||
142 | * JSON Response |
||
143 | * |
||
144 | * @param mixed $data |
||
145 | * @return string JSON Only for yii\web\Application, for console app returns `mixed` |
||
146 | */ |
||
147 | 27 | private function response($data) |
|
156 | } |
||
157 |