• Модуль: ui
  • Путь к файлу: ~/bitrix/modules/ui/lib/FileUploader/TempFile.php
  • Класс: BitrixUIFileUploaderTempFile
  • Вызов: TempFile::create
static function create(Chunk $chunk, UploaderController $controller): Result
{
	$result = new Result();
	$file = $chunk->getFile();
	if (!$file->isExists())
	{
		return $result->addError(new UploaderError(UploaderError::CHUNK_NOT_FOUND));
	}

	if (mb_strpos($file->getPhysicalPath(), CTempFile::getAbsoluteRoot()) !== 0)
	{
		// A chunk file could be saved in any folder.
		// Copy it to the temporary directory. We need to normalize the absolute path.
		$tempFilePath = self::generateLocalTempFile();
		if (!copy($chunk->getFile()->getPhysicalPath(), $tempFilePath))
		{
			return $result->addError(new UploaderError(UploaderError::CHUNK_COPY_FAILED));
		}

		$newFile = new IOFile($tempFilePath);
		if (!$newFile->isExists())
		{
			return $result->addError(new UploaderError(UploaderError::CHUNK_COPY_FAILED));
		}

		$chunk->setFile($newFile);
	}

	$tempFile = null;
	if ($chunk->isOnlyOne())
	{
		// Cloud and local files are processed by CFile::SaveFile.
		$tempFile = self::createTempFile($chunk, $controller);
	}
	else
	{
		// Multipart upload
		$bucket = self::findBucketForFile($chunk, $controller);
		if ($bucket)
		{
			// cloud file
			$tempFile = self::createTempFile($chunk, $controller, $bucket);
			$appendResult = $tempFile->appendToCloud($chunk);
			if (!$appendResult->isSuccess())
			{
				$chunk->getFile()->delete();
				$tempFile->delete();

				return $result->addErrors($appendResult->getErrors());
			}
		}
		else
		{
			// local file
			$localTempDir = self::generateLocalTempDir();
			if (!$file->rename($localTempDir))
			{
				return $result->addError(new UploaderError(UploaderError::FILE_MOVE_FAILED));
			}

			$tempFile = self::createTempFile($chunk, $controller);
		}
	}

	$result->setData(['tempFile' => $tempFile]);

	return $result;
}