Welcome Guest, Not a member yet? Register   Sign In
Very weird issue with corrupted files after downloading
#1

[eluser]Unknown[/eluser]
Hi All,

I have a wierd issue that I can't figure out. I use the download_helper to download PDF and Epub files. I have a download form on two different pages, both using a slightly different controller function to actually download the file, that means getting the correct filename.

In the end both functions end like:

//For PDF
$data = file_get_contents('/var/www/html/filename.pdf');
$name = 'myfile.pdf';

force_download($name, $data);

//For epub
$data = file_get_contents('/var/www/html/filename.epub');
$name = 'myfile.epub';

force_download($name, $data);


Here's the problem. If I use the download script from page A, going to controller X it is working as expected but if I use the script from page B, going to controller Y I'm having problems. According to Fiddler the file sent by the server (from controller Y) has 2 bites more then the actual file. The PDF also has 2 bites more but I can still open. The epub file (which is a special zip mimetype: application/epub+zip) will not open because it is corrupt.

How is it possible that actually the same script is given problems from location Y and not from location X. I've looked through the code and there is nothing different except the way I get the filenames.

bits, bytes and headers are not really my cup of tea, so after spending a whole day trying to figure it out I decided to post my question. Hopefully someone knows where to look for.

PS. The filesize is maximum 3MB. I tried a custom download script, also with readfile() but it is still the same problem. I don't think there's a problem in the download_helper but maybe on serverside?? I have no idea and I can't find anything on Google or in this forum.
Thanks in advance,




Theme © iAndrew 2016 - Forum software by © MyBB