1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
archiveentry.php
См. документацию.
1
<?php
2
namespace
Bitrix\Main\Engine\Response\Zip;
3
4
use Bitrix\Main\Application;
5
use Bitrix\Main\Config\Option;
6
use Bitrix\Main\Web\Uri;
7
use CFile;
8
13
class
ArchiveEntry
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
}
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\Engine\Response\Zip\ArchiveEntry
Определения
archiveentry.php:14
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\__construct
__construct()
Определения
archiveentry.php:42
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$path
$path
Определения
archiveentry.php:25
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getDocRoot
static getDocRoot()
Определения
archiveentry.php:193
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\setName
setName($name)
Определения
archiveentry.php:59
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getPath
getPath()
Определения
archiveentry.php:70
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getName
getName()
Определения
archiveentry.php:49
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getCrc32
getCrc32()
Определения
archiveentry.php:87
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$crc32
$crc32
Определения
archiveentry.php:37
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\createFromFile
static createFromFile(array $fileArray, $name=null)
Определения
archiveentry.php:152
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\__toString
__toString()
Определения
archiveentry.php:211
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\getSize
getSize()
Определения
archiveentry.php:79
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\createFromFilePath
static createFromFilePath($filePath, $name=null)
Определения
archiveentry.php:98
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$name
$name
Определения
archiveentry.php:19
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\$size
$size
Определения
archiveentry.php:31
Bitrix\Main\Engine\Response\Zip\ArchiveEntry\createFromFileId
static createFromFileId($fileId, $moduleId=null)
Определения
archiveentry.php:121
$filename
$filename
Определения
file_edit.php:47
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$moduleId
$moduleId
Определения
group_bizproc_workflow_delete.php:16
$docRoot
$docRoot
Определения
options.php:20
$context
$context
Определения
csv_new_setup.php:223
bitrix
modules
main
lib
engine
response
zip
archiveentry.php
Создано системой
1.14.0