I cannot seem to figure this issue out. I'm downloading a file (Moodle .mbz extension) using PHP with HTTP headers. The file is first downloaded from Amazon S3 to a server using the aws php sdk, which works fine. The issue is downloading the file from the server to another workstation. No matter what I seem to change, the md5 checksums for the file on the workstation and the file on the server do not match. Clients cannot restore the .mbz file they have downloaded to their workstation. It seems something is happening to the file to change it in some way but I cannot figure out what.
I have referenced: 1. this tutorial 2. This similar SO question and various other resources via google. I'm desperate, please help if you can. I have ensured compression is off in the httpd.conf file. Turned debugging completely off in php.ini. I can replicate the issue in both my development and staging environment.
Here's the code for the direct download:
<?php
if(!file_exists($filename))
{
// file does not exist
die('file '.$filename.' not found');
} else
{
$this->load->model('Job_model', 'job');
$save_as = $this->job->get_file_name_from_key($filename);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$save_as\"");
header("Expires: 0");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . filesize($filename));
readfile($filename);
}
Using PHP with codeigniter framework, if that's relevant.
Thank you!
Edit: An octal dump of the first 16 bytes shows that 4 spaces are being appended to the beginning of the file downloaded using the above code vs the file on the server.