Hummmmm, I got a big headache on downloading files for the past 3 hours. The issue is when I downloaded the files, I can't open it correctly. Such as txt, work and excel, they just return messy codes. What hell is it!
First, I thought it was the problem at upload side. So I check the upload method carefully. I use form upload. Then I tracked to the temp files I uploaded. They worked perfectly while opening. That must be the downloading side's problem.
There're some headers for downloading. There must be some outputs before these headers. So try to clean them and go for a coffee.
Use this function: ob_end_clean();
Work done! You are able to get what you uploaded now.