• Модуль: clouds
  • Путь к файлу: ~/bitrix/modules/clouds/classes/general/temp_file.php
  • Класс: CCloudTempFile
  • Вызов: CCloudTempFile::GetDirectoryName
static function GetDirectoryName($obBucket, $hours_to_keep_files = 0, $subdir = "")
{
	if ($hours_to_keep_files <= 0)
	{
		return self::GetFileName($obBucket,'');
	}

	$temp_path = ''; //This makes code analyzers happy. $temp_path will never be empty.
	if ($subdir === "")
	{
		$dir_name = self::GetAbsoluteRoot().'/BXTEMP-'.date('Y-m-d/H/', time() + 3600 * $hours_to_keep_files);
		$i = 0;
		while (true)
		{
			$i++;
			$dir_add = md5(mt_rand());
			$temp_path = $dir_name.$dir_add."/";

			if (!$obBucket->FileExists($temp_path))
			{
				break;
			}
		}
	}
	else //Fixed name during the session
	{
		$subdir = implode("/", (is_array($subdir) ? $subdir : array($subdir, bitrix_sessid())))."/";
		while (mb_strpos($subdir, "//") !== false)
		{
			$subdir = str_replace("//", "/", $subdir);
		}

		$bFound = false;
		for ($i = $hours_to_keep_files; $i > 0; $i--)
		{
			$dir_name = self::GetAbsoluteRoot().'/BXTEMP-'.date('Y-m-d/H/', time() + 3600 * $i);
			$temp_path = $dir_name.$subdir;

			$list = $obBucket->ListFiles($temp_path, true);
			if ($list['file'] || $list['dir'])
			{
				$bFound = true;
				break;
			}
		}

		if (!$bFound)
		{
			$dir_name = self::GetAbsoluteRoot().'/BXTEMP-'.date('Y-m-d/H/', time() + 3600 * $hours_to_keep_files);
			$temp_path = $dir_name.$subdir;
		}
	}

	if (!isset(self::$buckets[$obBucket->ID]))
	{
		self::$buckets[$obBucket->ID] = array(
			"bucket" => $obBucket,
			"filePath" => null
		);
	}
	self::RegisterShutdown();

	return $temp_path;
}