• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/virtual_io_filesystem.php
  • Класс: CBXVirtualFileFileSystem
  • Вызов: CBXVirtualFileFileSystem::PutContents
public function PutContents($data)
{
	$this->ClearErrors();

	$io = CBXVirtualIo::GetInstance();
	$dir = $io->CreateDirectory($this->GetPath());
	if (is_null($dir))
	{
		$this->AddError(sprintf("Can not create directory '%s' or access denied", $this->GetPath()));
		return false;
	}

	if ($this->IsExists() && !$this->IsWritable())
		$this->MarkWritable();

	$fd = fopen($this->GetPathWithNameEncoded(), "wb");
	if (!$fd)
	{
		$this->AddError(sprintf("Can not open file '%s' for writing", $this->GetPathWithNameEncoded()));
		return false;
	}
	if (fwrite($fd, $data) === false)
	{
		$this->AddError(sprintf("Can not write %d bytes to file '%s'", mb_strlen($data), $this->GetPathWithNameEncoded()));
		fclose($fd);
		return false;
	}
	fclose($fd);

	return true;
}