|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © MIKO LLC - All Rights Reserved |
|
4
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited |
|
5
|
|
|
* Proprietary and confidential |
|
6
|
|
|
* Written by Alexey Portnov, 6 2020 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace MikoPBX\PBXCoreREST\Controllers\Upload; |
|
10
|
|
|
|
|
11
|
|
|
use MikoPBX\Core\System\Util; |
|
12
|
|
|
use MikoPBX\PBXCoreREST\Controllers\BaseController; |
|
13
|
|
|
use Phalcon\Di; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* /api/upload/{name} |
|
17
|
|
|
* curl -F "[email protected]" http://127.0.0.1/pbxcore/api/upload/module -H 'Cookie: XDEBUG_SESSION=PHPSTORM' |
|
18
|
|
|
* curl -X POST -d '{"id": "1531474060"}' http://127.0.0.1/pbxcore/api/upload/status; -H 'Cookie: |
|
19
|
|
|
* XDEBUG_SESSION=PHPSTORM' |
|
20
|
|
|
*/ |
|
21
|
|
|
class PostController extends BaseController |
|
22
|
|
|
{ |
|
23
|
|
|
public function callAction($actionName): void |
|
24
|
|
|
{ |
|
25
|
|
|
$data = []; |
|
26
|
|
|
$data['result'] = 'ERROR'; |
|
27
|
|
|
$data['data'] = ''; |
|
28
|
|
|
|
|
29
|
|
|
if ($this->request->hasFiles() > 0) { |
|
30
|
|
|
$data = [ |
|
31
|
|
|
'resumableFilename' => $this->request->getPost('resumableFilename'), |
|
32
|
|
|
'resumableIdentifier' => $this->request->getPost('resumableIdentifier'), |
|
33
|
|
|
'resumableChunkNumber' => $this->request->getPost('resumableChunkNumber'), |
|
34
|
|
|
'resumableTotalSize' => $this->request->getPost('resumableTotalSize'), |
|
35
|
|
|
'upload_id' => time(), |
|
36
|
|
|
]; |
|
37
|
|
|
if (isset($data['resumableIdentifier'])){ |
|
38
|
|
|
$data['upload_id'] = (int) filter_var($data['resumableIdentifier'], FILTER_SANITIZE_NUMBER_INT); |
|
39
|
|
|
} |
|
40
|
|
|
foreach ($this->request->getUploadedFiles() as $file) { |
|
41
|
|
|
$data['files'][]= [ |
|
42
|
|
|
'file_path' => $file->getTempName(), |
|
43
|
|
|
'file_size' => $file->getSize(), |
|
44
|
|
|
'file_error'=> $file->getError(), |
|
45
|
|
|
'file_name' => $file->getName(), |
|
46
|
|
|
'file_type' => $file->getType() |
|
47
|
|
|
]; |
|
48
|
|
|
if ($file->getError()) { |
|
49
|
|
|
$data['data'] = 'error ' . $file->getError() . ' in file ' . $file->getTempName(); |
|
50
|
|
|
$this->sendError(400, $data['data']); |
|
51
|
|
|
Util::sysLogMsg('UploadFile', 'error ' . $file->getError() . ' in file ' . $file->getTempName()); |
|
52
|
|
|
return; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
$actionName = 'uploadResumable'; |
|
56
|
|
|
} elseif ($actionName === 'status') { |
|
57
|
|
|
$row_data = $this->request->getRawBody(); |
|
58
|
|
|
$data = json_decode($row_data, true); |
|
59
|
|
|
} |
|
60
|
|
|
$this->sendRequestToBackendWorker('upload', $actionName, $data); |
|
61
|
|
|
} |
|
62
|
|
|
} |