Whenever a fragment of the Quran was revealed, the Prophet called one of his literate companions and dictated it to him, and setting the exact position of the new fragment in the fabric of what had already been received.
Muhammad then asked the scribe to repeat back what he dictated so that he could correct any deficiencies.
Another famous story tells how every year in the month of Ramadan, the Prophet would recite the whole of the Quran (so far revealed) to Gabriel.
Since that day, Muslims recite the whole Quran during the month of Ramadan. The head scribe of the Quran was Zaid Ibn Thabit who was present at the final compilation of the Quran text.
Extremely diverse materials were used when recording: parchment, leather, wooden tablets, camels' scapula, soft stone for inscriptions, etc.
At the same time however, Muhammad encouraged the faithful to learn the Quran by heart. Many memorized the entire Quran by heart and helped to spread it abroad.
By preserving the Quran text both in writings (on materials) and by human memorization proved invaluable in the preservation of the entire text.