Nice question! I think the key here is to look at the context. Both quotes are included in The Sermon on the Mount (Matthew 5-7); both are spoken by Jesus and probably both were spoken on the same day.
First the context. Jesus says (in Matthew 5:13-16):
‘You are the salt of the earth. But if the salt loses its saltiness, how can it be made salty again? It is no longer good for anything, except to be thrown out and trampled underfoot.
‘You are the light of the world. A town built on a hill cannot be hidden. Neither do people light a lamp and put it under a bowl. Instead they put it on its stand, and it gives light to everyone in the house. In the same way, let your light shine before others, that they may see your good deeds and glorify your Father in heaven.
I interpret this to mean we should be doing good deeds for other people because this will encourage them to glorify God. So our motivation is to help people to turn to God, not to bring glory to ourselves.
Again the context; Jesus says (in Matthew 6:1-4):
‘Be careful not to practise your righteousness in front of others to be seen by them. If you do, you will have no reward from your Father in heaven.
‘So when you give to the needy, do not announce it with trumpets, as the hypocrites do in the synagogues and on the streets, to be honoured by others. Truly I tell you, they have received their reward in full. But when you give to the needy, do not let your left hand know what your right hand is doing, so that your giving may be in secret. Then your Father, who sees what is done in secret, will reward you.
This clarifies what I said above - the glory should not go to us. But note this is specifically talking about giving. If a number of people give to a church (or temple or synagogue, in this case), then the church can then in turn give to the needy. The recipients will then hopefully praise God, knowing only that this was given in His name but not knowing specifically by whom.
Giving can be anonymous in a way that other forms of light (eg visiting the sick or those in prison) are not.
Also, giving (like the things that follow in chapter 6: prayer and fasting) is between you and God - so only God needs to know about it.