Chunk::getContentRange

  1. Bitrix24 API (v. 23.675.0)
  2. ui
  3. Chunk
  4. getContentRange
  • Модуль: ui
  • Путь к файлу: ~/bitrix/modules/ui/lib/FileUploader/Chunk.php
  • Класс: BitrixUIFileUploaderChunk
  • Вызов: Chunk::getContentRange
static function getContentRange(HttpRequest $request): Result
{
	$contentRange = $request->getHeader('Content-Range');
	if ($contentRange === null)
	{
		return new Result();
	}

	$result = new Result();
	if (!preg_match('/(d+)-(d+)/(d+)$/', $contentRange, $match))
	{
		return $result->addError(new UploaderError(UploaderError::INVALID_CONTENT_RANGE));
	}

	[$startRange, $endRange, $fileSize] = [(int)$match[1], (int)$match[2], (int)$match[3]];

	if ($startRange > $endRange)
	{
		return $result->addError(new UploaderError(UploaderError::INVALID_CONTENT_RANGE));
	}

	if ($fileSize <= $endRange)
	{
		return $result->addError(new UploaderError(UploaderError::INVALID_CONTENT_RANGE));
	}

	$result->setData([
		'startRange' => $startRange,
		'endRange' => $endRange,
		'fileSize' => $fileSize,
	]);

	return $result;
}

Добавить комментарий