Thickness-driven spin reorientation transition in ultrathin films