I'm assuming that you want to list the picture for shepard with the dog shepard.
one are the dogs in a DB if so when you upload the picture do you tell the DB to refer to this picture the name of the file is not important it's what you tell the DB to look for when you upload the pic
so a siple way would be on upload update the DB with a field that stores the name of the picture you uploaded
$sql = "UPDATE $table SET
pic_name = '$file' WHERE dog_id = '$dog_id'
and on your reference page use something like this
<A HERF=\"$dir/$path/$pic_name.$image_type\">
Something Like this should work fine