Problem with incorrect md5sum

I have a php function which allows users to download files from our archive site in England. The main site is in the U.S. and that function is working correctly. The UK function results in the files having incorrect md5sums. I've gone through it multiple times and can't find any spaces where they shouldn't be and that there's no processing before the header code. I've attached a copy of the code in case someone would like to take a look and maybe spot something I've missed that could be causing this problem.

Thanks in advance.