This code is more generic and support all cases. Previously we had bug where the user lost his image path if the image was not located in image directory.