private function rmdir($dir, $recursive)
	{
		$is_link = is_link($dir);
		if($is_link)
		{
			if(! unlink($dir))
				throw new Exception("Error unlinking $dir");
		}
		else if(! $recursive)
		{
			if(! rmdir($dir))
				throw new Exception("Error removing temp dir: $dir");
		}
		else
		{
			$dh = opendir($dir);
			if(! $dh)
				throw new Exception("Cannot read temp dir contents for removal: $dir");

			do
			{
				$file = readdir($dh);
				if($file === false)
					break;

				// Don't delete current dir or parent dir (yet)
				if($file === '.' || $file === '..')
					continue;

				$path = $dir .DIRECTORY_SEPARATOR. $file;

				$is_link = is_link($path);
				$is_dir = is_dir($path);

				if($is_dir && ! $is_link)
				{
					$this->rmdir($path, true);
				}
				else // anything else, should be able to unlink
				{
					if(! unlink($path))
						throw new Exception("Cannot remove nested temp file: $path");
				}
			}
			while($file !== false);

			closedir($dh);

			// Now remove the dir itself (non-recursive, it should now be empty)
			$this->rmdir($dir, false);
		}
	}