• Модуль: rest
  • Путь к файлу: ~/bitrix/modules/rest/classes/general/rest_util.php
  • Класс: CRestUtil
  • Вызов: CRestUtil::saveFile
static function saveFile($fileContent, $fileName = "")
{
	if(is_array($fileContent))
	{
		list($fileName, $fileContent) = array_values($fileContent);
	}

	if($fileContent <> '' && $fileContent !== 'false') // let it be >0
	{
		$fileContent = base64_decode($fileContent);
		if($fileContent !== false && $fileContent <> '')
		{
			if($fileName == '')
			{
				$fileName = SecurityRandom::getString(32);
			}
			else
			{
				$fileName = BitrixMainTextEncoding::convertEncoding($fileName, LANG_CHARSET, 'utf-8');
			}

			$fileName = CTempFile::GetFileName($fileName);

			if(CheckDirPath($fileName))
			{
				file_put_contents($fileName, $fileContent);
				return CFile::MakeFileArray($fileName);
			}
		}
		else
		{
			return null; // wrong file content
		}
	}

	return false;
}