I am trying to download a binary file from the server that uses PHP. Somehow it randomly adds one byte at the front of the file, when downloading it:
Result download (Hex editor image):
Expected result download (Hex editor image):
Things i have tried:
1. Headers aproach try 1
$filename = 'spss-export.sav';
header("Content-Disposition: attachment; filename=survey_2_SPSS_syntax_file.sav");
header("Content-type: application/download; charset=UTF-8");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
readfile($filename); // do the double-download-dance (dirty but worky)
exit;
2. Header aproach try 2
$filename = 'spss-export.sav';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($filename) . "\"");
readfile($filename); // do the double-download-dance (dirty but worky)
exit;
3. Laravel response download
$filename = 'spss-export.sav';
return response()->download($filename);
Header aproaches produce files that only have the random byte at the begining, but laravel aproach produces the random byte and one missing byte at the end of file. Anyone knows what might be the problem?