I want to determine the time a photon needs in order to cover a distance, say $l_0$, where $l_0$ is the length of a spaceship (reference system S'). So, the photon is going from one end of the spaceship to another. But, what I am after is the time elapsed between the two events in the system of reference of an observer that is located outside the spaceship (reference system S). My attempt is as follows: we know that the speed of light $c$ is constant in all frames of rerefence, so
$$c=\frac{l_0}{t'}=\frac{l}{t}$$
Therefore, the time needed to cover the distance is $t$ and
$$t=\frac{l}{c}=\gamma\frac{l_0}{c}$$
Is this line of reasoning correct, or should the velocity of light in the reference frame S be something else? If it should be something else, then why?
Thanks in advance.