1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
archiveentry.php
См. документацию.
1<?php
2namespace Bitrix\Main\Engine\Response\Zip;
3
4use Bitrix\Main\Application;
5use Bitrix\Main\Config\Option;
6use Bitrix\Main\Web\Uri;
7use CFile;
8
14{
19 protected $name;
20
25 protected $path;
26
31 protected $size;
32
37 protected $crc32;
38
42 protected function __construct()
43 {}
44
49 public function getName()
50 {
51 return $this->name;
52 }
53
59 public function setName($name)
60 {
61 $this->name = $name;
62
63 return $this;
64 }
65
70 public function getPath()
71 {
72 return $this->path;
73 }
74
79 public function getSize()
80 {
81 return $this->size;
82 }
83
87 public function getCrc32()
88 {
89 return $this->crc32;
90 }
91
98 public static function createFromFilePath($filePath, $name = null)
99 {
100 $fileArray = CFile::MakeFileArray($filePath);
101
102 if (\is_array($fileArray))
103 {
104 return self::createFromFile([
105 'ID' => 0,
106 'ORIGINAL_NAME' => $fileArray['name'],
107 'FILE_SIZE' => $fileArray['size'],
108 'SRC' => mb_substr($fileArray['tmp_name'], mb_strlen(self::getDocRoot())),
109 ], $name);
110 }
111
112 return null;
113 }
114
121 public static function createFromFileId($fileId, $moduleId = null)
122 {
123 $fileArray = CFile::getFileArray($fileId);
124
125 // check file exists
126 if (!\is_array($fileArray) || empty($fileArray['SRC']))
127 {
128 return null;
129 }
130
131 // check module restriction
132 if (
133 $moduleId !== null &&
134 (
135 !isset($fileArray['MODULE_ID']) ||
136 $fileArray['MODULE_ID'] !== $moduleId
137 )
138 )
139 {
140 return null;
141 }
142
143 return self::createFromFile($fileArray);
144 }
145
152 protected static function createFromFile(array $fileArray, $name = null)
153 {
154 $zipEntry = new static();
155 $zipEntry->setName($name?: $fileArray['ORIGINAL_NAME']);
156 $zipEntry->size = (int)$fileArray['FILE_SIZE'];
157
158 if (empty($fileArray['SRC']))
159 {
160 $fileArray['SRC'] = CFile::getFileSrc($fileArray);
161 }
162
163 $fromClouds = false;
164 $filename = $fileArray['SRC'];
165 if (isset($fileArray['HANDLER_ID']) && !empty($fileArray['HANDLER_ID']))
166 {
167 $fromClouds = true;
168 }
169
170 if ($fromClouds)
171 {
172 $filename = preg_replace('~^(http[s]?)(\://)~i', '\\1.' , $filename);
173 $cloudUploadPath = Option::get(
174 'main',
175 'bx_cloud_upload',
176 '/upload/bx_cloud_upload/'
177 );
178 $zipEntry->path = $cloudUploadPath . $filename;
179 }
180 else
181 {
182 $zipEntry->path = $filename;
183 }
184 $zipEntry->path = Uri::urnEncode($zipEntry->path, 'UTF-8');
185
186 return $zipEntry;
187 }
188
193 protected static function getDocRoot()
194 {
195 static $docRoot = null;
196
197 if ($docRoot === null)
198 {
199 $context = Application::getInstance()->getContext();
200 $server = $context->getServer();
201 $docRoot = $server->getDocumentRoot();
202 }
203
204 return $docRoot;
205 }
206
211 public function __toString()
212 {
213 $crc32 = $this->getCrc32()?: '-';
214 $name = $this->getName();
215
216 return "{$crc32} {$this->getSize()} {$this->getPath()} {$name}";
217 }
218}
static getInstance()
Определения application.php:98
Определения archiveentry.php:14
__construct()
Определения archiveentry.php:42
$path
Определения archiveentry.php:25
static getDocRoot()
Определения archiveentry.php:193
setName($name)
Определения archiveentry.php:59
getPath()
Определения archiveentry.php:70
getName()
Определения archiveentry.php:49
getCrc32()
Определения archiveentry.php:87
$crc32
Определения archiveentry.php:37
static createFromFile(array $fileArray, $name=null)
Определения archiveentry.php:152
__toString()
Определения archiveentry.php:211
getSize()
Определения archiveentry.php:79
static createFromFilePath($filePath, $name=null)
Определения archiveentry.php:98
$name
Определения archiveentry.php:19
$size
Определения archiveentry.php:31
static createFromFileId($fileId, $moduleId=null)
Определения archiveentry.php:121
$filename
Определения file_edit.php:47
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$moduleId
$docRoot
Определения options.php:20
$context
Определения csv_new_setup.php:223