3namespace Bitrix\UI\FileUploader;
7use Bitrix\Main\HttpRequest;
10use Bitrix\Main\Text\Encoding;
34 $fileMimeType = (string)
$request->getHeader(
'Content-Type');
35 if (!preg_match(
'~\w+/[-+.\w]+~', $fileMimeType))
40 $contentLength =
$request->getHeader(
'Content-Length');
41 if ($contentLength ===
null)
46 $contentLength = (int)$contentLength;
47 $filename = static::normalizeFilename((
string)
$request->getHeader(
'X-Upload-Content-Name'));
58 $contentRangeResult = static::getContentRange(
$request);
59 if (!$contentRangeResult->isSuccess())
61 return $result->addErrors($contentRangeResult->getErrors());
64 $file = static::getFileFromHttpInput();
65 $contentRange = $contentRangeResult->getData();
66 $rangeChunkSize = empty($contentRange) ? 0 : ($contentRange[
'endRange'] - $contentRange[
'startRange'] + 1);
68 if ($rangeChunkSize && $contentLength !== $rangeChunkSize)
73 'rangeChunkSize' => $rangeChunkSize,
74 'contentLength' => $contentLength,
80 if ($chunk->getSize() !== $contentLength)
85 'chunkSize' => $chunk->getSize(),
86 'contentLength' => $contentLength,
92 $chunk->setType($fileMimeType);
94 if (!empty($contentRange))
96 $chunk->setStartRange($contentRange[
'startRange']);
97 $chunk->setEndRange($contentRange[
'endRange']);
98 $chunk->setFileSize($contentRange[
'fileSize']);
101 $result->setData([
'chunk' => $chunk]);
106 private static function getFileFromHttpInput():
IO\
File
116 private static function getContentRange(HttpRequest
$request): Result
118 $contentRange =
$request->getHeader(
'Content-Range');
119 if ($contentRange ===
null)
125 if (!preg_match(
'/(\d+)-(\d+)\/(\d+)$/', $contentRange, $match))
151 private static function normalizeFilename(
string $filename): string
159 private static function isValidFilename(
string $filename): bool
166 if (mb_strpos(
$filename,
'\0') !==
false)
265 return $this->startRange ===
null || $this->startRange === 0;
270 return $this->endRange ===
null || ($this->endRange + 1) === $this->fileSize;
276 $this->startRange ===
null
277 || ($this->startRange === 0 && ($this->endRange - $this->startRange + 1) === $this->fileSize)
285 if (in_array(mb_strtolower($this->
getName()), $config->getIgnoredFileNames()))
290 if (
$config->getMaxFileSize() !==
null && $this->getFileSize() >
$config->getMaxFileSize())
296 'maxFileSize' => \CFile::formatSize(
$config->getMaxFileSize()),
297 'maxFileSizeInBytes' =>
$config->getMaxFileSize(),
303 if ($this->
getFileSize() < $config->getMinFileSize())
309 'minFileSize' => \CFile::formatSize(
$config->getMinFileSize()),
310 'minFileSizeInBytes' =>
$config->getMinFileSize(),
316 if (!$this->validateFileType(
$config->getAcceptedFileTypes()))
325 $image =
new File\Image($this->
getFile()->getPhysicalPath());
326 $imageInfo = $image->getInfo(
false);
329 if (
$config->getIgnoreUnknownImageTypes())
341 $width = $imageInfo->getWidth();
342 $height = $imageInfo->getHeight();
343 if ($imageInfo->getFormat() ===
File\Image::FORMAT_JPEG)
345 $exifData = $image->getExifData();
346 if (isset($exifData[
'Orientation']) && $exifData[
'Orientation'] >= 5 && $exifData[
'Orientation'] <= 8)
352 if (!
$config->shouldTreatOversizeImageAsFile())
355 $imageData->setWidth(
$width);
356 $imageData->setHeight(
$height);
358 $validationResult =
$config->validateImage($imageData);
359 if (!$validationResult->isSuccess())
361 return $result->addErrors($validationResult->getErrors());
371 private function validateFileType(
array $fileTypes): bool
373 if (
count($fileTypes) === 0)
379 $baseMimeType = preg_replace(
'/\/.*$/',
'', $mimeType);
381 foreach ($fileTypes as
$type)
383 if (!is_string(
$type) || mb_strlen(
$type) === 0)
389 if (
$type[0] ===
'.')
400 if ($baseMimeType === preg_replace(
'/\/.*$/',
'',
$type))
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
putContents($data, $flags=self::REWRITE)
static createFromRequest(HttpRequest $request)
__construct(IO\File $file)
setStartRange(int $startRange)
validate(Configuration $config)
setFileSize(int $fileSize)
setEndRange(int $endRange)
static generateLocalTempFile()
const FILE_NAME_NOT_ALLOWED
const MAX_FILE_SIZE_EXCEEDED
const INVALID_CONTENT_TYPE
const INVALID_CONTENT_NAME
const FILE_TYPE_NOT_ALLOWED
const INVALID_CONTENT_RANGE
const MIN_FILE_SIZE_EXCEEDED
const IMAGE_TYPE_NOT_SUPPORTED
const INVALID_CONTENT_LENGTH
hidden PROPERTY[<?=$propertyIndex?>][CODE]<?=htmlspecialcharsEx( $propertyCode)?> height
bx popup label bx width30 PAGE_NEW_MENU_NAME text width
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"