Heavy quarks are copiously produced in two-photon collisions at $e^+e^-$ colliders. The theoretical predictions including QCD radiative corrections are compared to recent experimental data on $\gamma\gamma$ production of charm quarks at PETRA, PEP, TRISTAN and LEP. Photoproduction of heavy quarks at HERA is an important tool to measure the gluon distribution in the proton. New theoretical results on heavy quark photoproduction at large transverse momenta are discussed and NLO predictions for inelastic $J/\psi$ photoproduction in the HERA energy range are given. The sensitivity of the results to the parametrization of the gluon distribution in the small-$x$ region is demonstrated.