Can the Bible be infallible if it is written by fallible humans? And if not, how can we accept it as literal truth?

There is no logical reason why this could not be true. After all, even fallible humans can get things right some of the time, especially if they are supervised by Someone who is infallible.

Christians do not claim that the humans who penned the books of the Bible were always accurate in everything they said or did. We simply believe that the Bible is right when it claims that God guided these men in their task of writing Scripture, in such a way that the result is an infallible book. The apostlePeter undoubtedly said some foolish things during his lifetime, but God did not allow him to clutter up the Bible with any of those blunders.

One standard explanation of the concept of “inspiration” is given by Ryrie:

God's superintendence of the human authors so that, using their own individual personalities, they composed and recorded without error His revelation to man in the words of the original autographs [Charles Ryrie, A Survey of Bible Doctrine (Chicago: Moody Press, 1972), p. 38].

We do not know exactly how God accomplished His purpose of providing a totally accurate Bible. But 2 Peter 1:21 gives some insight:

No prophecy was ever made by an act of human will, but men moved by the Holy Spirit spoke from God.

The word “moved” in this verse is also used in Acts 27:15 to describe the way a great storm blew the apostlePaul'sship off course across the Mediterranean. The people on board could spend the time as they chose (either bailing or wailing!), but the storm determined their destination of Malta. Similarly, God guided the writers of Scripture to produce exactly the message He wanted.