I'm trying to set up a binary file download that opens the normal browser "save as" dialog box. Instead, the file is displayed as characters in the browser window. I have read the threads here that talk about setting the headers correctly for a binary download, and tried many different approaches, but nothing seems to help. I've also tried both readfile and fpassthru, both functions just dump the file to the screen.
Here is the latest version of the code, I would appreciate suggestions.
$fp = fopen($file, "rb");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-type: application/octet-stream");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ". filesize($file));
//readfile("$file");
fpassthru($fp);