Loading and Referencing Images

Could be the piece you’re missing here is that after you upload photos if you want to get to that item again to do anything with it, including get its URL, the thing you need to keep is not the filename but the ID that you get back.

You can then call e.g. wp_get_attachment_image_src directly with that ID to get the URL for that image.

If you don’t have a way to store that ID in a useful place and recall it when you need it, you may need to resort to some other way to figure it out, such as what you’re doing.

Does that help?