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

	if (mb_substr($path, 0, mb_strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
	{
		$pathTmp = mb_substr($path, mb_strlen($_SERVER["DOCUMENT_ROOT"]));
		if (empty($pathTmp) || $pathTmp == '/')
		{
			$this->AddError("Can not delete the root folder of the project");
			return false;
		}
	}

	$pathEncoded = CBXVirtualIoFileSystem::ConvertCharset($path);

	$f = true;
	if (is_file($pathEncoded) || is_link($pathEncoded))
	{
		if (@unlink($pathEncoded))
			return true;

		$this->AddError(sprintf("Can not delete file '%s'", $path));
		return false;
	}
	elseif (is_dir($pathEncoded))
	{
		if ($handle = opendir($pathEncoded))
		{
			while (($file = readdir($handle)) !== false)
			{
				if ($file == "." || $file == "..")
					continue;

				$pathDecodedTmp = CBXVirtualIoFileSystem::ConvertCharset($pathEncoded."/".$file, CBXVirtualIoFileSystem::directionDecode);
				if (!$this->Delete($pathDecodedTmp))
					$f = false;
			}
			closedir($handle);
		}
		if (!@rmdir($pathEncoded))
		{
			$this->AddError(sprintf("Can not delete directory '%s'", $path));
			return false;
		}

		return $f;
	}

	$this->AddError("Unknown error");
	return false;
}