Filariform larvae penetrate human skin, reach the lungs via blood vessels, penetrate into pulmonary alveoli, ascend the respiratory tree to the epiglottis, and are swallowed. The larvae develop into adults that attach to the wall of the small bowel, feeding on blood.
Thus you can see that most worms in filariform larvae reach the intestine from lungs via pharynx. If you swallow sphlegm, filariform larvae will also go down to the stomach. Moreover if you got stomach ulcer, the bacteria present in the sphlegm may also likely to contaminate the ulcer.