Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
fileinputreceiver.php
1
<?php
2
3
namespace
Bitrix\Main\UI
;
4
5
use
Bitrix\Main\AccessDeniedException
;
6
use
Bitrix\Main\Localization\Loc
;
7
use
Bitrix\Main\Security\Sign\Signer
;
8
use
Bitrix\Main\UI\Uploader\Uploader
;
9
10
class
FileInputReceiver
11
{
12
protected
$status
= array();
13
protected
$id
=
"unknown"
;
14
protected
$uploader
;
15
16
const
STATUS_SUCCESS
=
'success'
;
17
const
STATUS_DENIED
=
'denied'
;
18
const
STATUS_ERROR
=
'error'
;
19
const
STATUS_NEED_AUTH
=
'need_auth'
;
20
const
STATUS_INVALID_SIGN
=
'invalid_sign'
;
21
22
function
__construct
($signature)
23
{
24
global $USER;
25
26
if
(!$USER->IsAuthorized())
27
throw
new
AccessDeniedException
(
Loc::getMessage
(
"BXU_AccessDenied_Authorize"
));
28
29
$sign =
new
Signer
;
30
$params = unserialize(base64_decode($sign->unsign($signature,
"fileinput"
)), [
"allowed_classes"
=>
false
]);
31
$this->
id
= $params[
"id"
];
32
33
$this->uploader =
new
Uploader
($params);
34
$this->uploader->setHandler(
"onFileIsUploaded"
, array($this,
"handleFile"
));
35
}
36
protected
function
getAgent
()
37
{
38
return
$this->uploader
;
39
}
40
41
public
static
function
sign
($params = array())
42
{
43
$sign =
new
Signer
();
44
return
$sign->sign(base64_encode(serialize($params)),
"fileinput"
);
45
}
46
47
48
protected
static
function
handleFileByPath
(&$file)
49
{
50
$key =
"default"
;
51
52
$docRoot = \CBXVirtualIo::GetInstance()->CombinePath(\CTempFile::GetAbsoluteRoot());
53
$file[
"files"
][$key][
"path"
] = \CBXVirtualIo::GetInstance()->GetFile($file[
"files"
][$key][
"tmp_name"
])->GetPathWithName();
54
if
(mb_strpos($file[
"files"
][$key][
"path"
], $docRoot) === 0)
55
$file[
"files"
][$key][
"path"
] = str_replace(
"//"
,
"/"
,
"/"
.mb_substr($file[
"files"
][$key][
"path"
], mb_strlen($docRoot)));
56
57
$file[
"files"
][$key][
"tmp_url"
] = $file[
"files"
][$key][
"url"
];
58
$file[
"type"
] = $file[
"files"
][$key][
"type"
];
59
60
return
true
;
61
}
62
63
protected
static
function
handleFileByHash
($hash, &$file)
64
{
65
$file[
"uploadId"
] = $hash;
66
return
true
;
67
}
68
69
public
function
handleFile
($hash, &$file)
70
{
71
if
($this->
id
==
"path"
)
72
{
73
return
self::handleFileByPath
($file);
74
}
75
return
self::handleFileByHash
($hash, $file);
76
}
77
78
public
function
exec
()
79
{
80
$this->
getAgent
()->checkPost();
81
}
82
}
Bitrix\Main\AccessDeniedException
Definition
exception.php:214
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Security\Sign\Signer
Definition
signer.php:13
Bitrix\Main\UI\FileInputReceiver
Definition
fileinputreceiver.php:11
Bitrix\Main\UI\FileInputReceiver\STATUS_INVALID_SIGN
const STATUS_INVALID_SIGN
Definition
fileinputreceiver.php:20
Bitrix\Main\UI\FileInputReceiver\STATUS_ERROR
const STATUS_ERROR
Definition
fileinputreceiver.php:18
Bitrix\Main\UI\FileInputReceiver\getAgent
getAgent()
Definition
fileinputreceiver.php:36
Bitrix\Main\UI\FileInputReceiver\handleFileByPath
static handleFileByPath(&$file)
Definition
fileinputreceiver.php:48
Bitrix\Main\UI\FileInputReceiver\STATUS_DENIED
const STATUS_DENIED
Definition
fileinputreceiver.php:17
Bitrix\Main\UI\FileInputReceiver\handleFileByHash
static handleFileByHash($hash, &$file)
Definition
fileinputreceiver.php:63
Bitrix\Main\UI\FileInputReceiver\$status
$status
Definition
fileinputreceiver.php:12
Bitrix\Main\UI\FileInputReceiver\$uploader
$uploader
Definition
fileinputreceiver.php:14
Bitrix\Main\UI\FileInputReceiver\sign
static sign($params=array())
Definition
fileinputreceiver.php:41
Bitrix\Main\UI\FileInputReceiver\__construct
__construct($signature)
Definition
fileinputreceiver.php:22
Bitrix\Main\UI\FileInputReceiver\handleFile
handleFile($hash, &$file)
Definition
fileinputreceiver.php:69
Bitrix\Main\UI\FileInputReceiver\exec
exec()
Definition
fileinputreceiver.php:78
Bitrix\Main\UI\FileInputReceiver\STATUS_SUCCESS
const STATUS_SUCCESS
Definition
fileinputreceiver.php:16
Bitrix\Main\UI\FileInputReceiver\$id
$id
Definition
fileinputreceiver.php:13
Bitrix\Main\UI\FileInputReceiver\STATUS_NEED_AUTH
const STATUS_NEED_AUTH
Definition
fileinputreceiver.php:19
Bitrix\Main\UI\Uploader\Uploader
Definition
uploader.php:167
Bitrix\Main\UI
modules
main
lib
ui
fileinputreceiver.php
Создано системой
1.10.0