Measurement of inelastic J/ψ and ψ′ photoproduction at HERA