Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
fileinputreceiver.php
1<?php
2
3namespace Bitrix\Main\UI;
4
9
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}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static handleFileByHash($hash, &$file)