It is indeed only Allah who has given man whatever he possesses. Man's life and all his belongings are the bounties of Allah. The only befitting way man can express his gratitude to acknowledge this truth is by presenting everything he has in his possession at the disposal of Allah. Spending a part of one's wealth in the way of Allah is only a symbolic expression of that attitude.
Whatever one earns is attributable to the fact that God has given man the physical abilities to earn it: hands to work with, eyes and tongue to see and speak with, mind to plan with. Moreover, He has given man to live in a world which is completely subservient to him. Everything in this world has been designed in such a manner that man can use it to the best of his advantage. If it were not the case, man despite possessing all his physical and mental abilities could not have been able to usefully employ them. If the seeds of wheat were not able to grow, but instead continued to languish like pebbles in the dust, man could not have been able to get the sort of flourishing crops he now gets as his food. Likewise, if nature refused to play its subservient role, generating electricity would have become impossible; similarly all transportation facilities would come to a standstill. The truth is that in the present world man earns only as a direct consequence of God's graciousness. The right return for this kindness is that man should spend his earnings in the way of Allah. He should use his wealth to help out the poor people. He should spend his God-given wealth on God-proposed avenues.
The only spending that can qualify to be described as having been done in the way of Allah is the one that is meant to please Allah alone, not the one that is done for earning fame, respect or reward. Man normally spends wealth to get away from the troubles of this world; wealth spent in the way of Allah is so done to save one from the troubles of the Hereafter.