Excerpts from Books and Wikipedia
"The war [Peninsular War] began when the French and Spanish armies invaded and occupied Portugal in 1807 by transiting through Spain, and it escalated in 1808 after Napoleonic France had occupied Spain, which had been its ally. Napoleon Bonaparte forced the abdications of Ferdinand VII and his father Charles IV and then installed his brother Joseph Bonaparte on the Spanish throne and promulgated the Bayonne Constitution. Most Spaniards rejected French rule and fought a bloody war to oust them. The war on the peninsula lasted until the Sixth Coalition defeated Napoleon in 1814, and it is regarded as one of the first wars of national liberation and is significant for the emergence of large-scale guerrilla warfare." [Wikipedia]