Para mi entender creo que el problema esta en
header ("Content-Type: application/octet-stream");
Te sugiero que coloques mejor el tipo de archivo que quieres bajar. Por ejemplo si quieres bajar un pdf te sugiero que uses
header('Content-type: application/pdf');
Ejemplo de
php.net Código PHP:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');
?>