Upconversion nanocrystals with small size and strong fluorescent signals own great potential in applications such as biomolecule-labeling, in vivo tracking and molecular imaging. Herein we reported that NaYbF4: 25%Gd, 2%Tm upconversion nanocrystals with small size and strong fluorescent signals were controllably synthesized by oleic acid (OA)/ ionic liquid (IL) two-phase system for targeted fluorescent imaging of gastric cancer in vivo. The optimal synthesis condition of NaYbF4: 25%Gd, 2%Tm upconversion nanocrystals by OA/IL two-phase system was established, adding more metal ion such as Na(+) ion could facilitate the size control and crystal-phase transition, more importantly, markedly enhancing fluorescent intensity of beta-phase nanocrystals compared with traditional methods. Alpha-phase NaYbF4, 2%Tm upconversion nanocrystals with less than 10nm in diameter and beta-phase NaYbF4: 25%Gd, 2%Tm upconversion nanocrystals with 30 nm or so in diameter and strong fluorescent signals were obtained, these synthesized nanocrystals exhibited very low cytotoxicity. Folic acid-conjugated silica-modified beta-phase NaYbF4: 25%Gd, 2%Tm upconversion nanocrystals were prepared, could actively target gastric cancer tissues implanted into nude mice in vivo, and realized targeted fluorescent imaging. Folic acid-conjugated silica-modified NaYbF4: 25%Gd, 2%Tm upconversion nanocrystals show great potential in applications such as targeted near infared radiation fluorescent imaging, magnetic resonance imaging and targeted therapy of gastric cancer in the near future.