• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/web/http/multipartstream.php
  • Класс: BitrixMainWebHttpMultipartStream
  • Вызов: MultipartStream::build
protected function build(array $data)
{
	$boundary = $this->getBoundary();

	foreach ($data as $k => $v)
	{
		$this->write('--' . $boundary . "rn");

		if ((is_resource($v) && get_resource_type($v) === 'stream') || is_array($v))
		{
			$filename = $v['filename'] ?? $k;
			$contentType = $v['contentType'] ?? 'application/octet-stream';

			$this->write('Content-Disposition: form-data; name="' . $k . '"; filename="' . $filename . '"' . "rn");
			$this->write('Content-Type: ' . $contentType . "rnrn");

			if (is_array($v))
			{
				if (isset($v['resource']) && is_resource($v['resource']) && get_resource_type($v['resource']) === 'stream')
				{
					fseek($v['resource'], 0);
					while (!feof($v['resource']))
					{
						$this->write(stream_get_contents($v['resource'], static::BUF_LEN));
					}
				}
				else
				{
					if (isset($v['content']))
					{
						$this->write($v['content']);
					}
					else
					{
						throw new ArgumentException("File `{$k}` not found for multipart upload.", 'data');
					}
				}

			}
			else
			{
				fseek($v, 0);
				while (!feof($v))
				{
					$this->write(stream_get_contents($v, static::BUF_LEN));
				}
			}
		}
		else
		{
			$this->write('Content-Disposition: form-data; name="' . $k . '"' . "rnrn");
			$this->write($v);
		}

		$this->write("rn");
	}

	$this->write('--' . $boundary . "--rn");
}