View Full Version : Resolved HTTP Headers download problem

04-15-2012, 05:13 PM
Hey, I've wrote a script which creates a .pem file, once the form has been submitted I'm trying to send the file using headers, but the file it outputs is a different size to the one that the script creates. The original file works fine, but downloaded one won't open. Here is the code I'm using to download the file.

$filename = urlencode($filename);
$fullpath = realpath("keys/$filename");
$size = filesize("keys/$filename");
header('Cache Control: public');
header("Content-Description: File Transfer");
header("Content-Length:" . $size);
header("Content-Disposition: attachment; filename=" . basename($fullpath));
header("Content-Type: application/x-pem-file");
header("Content-Transfer-Encoding: binary");

Any ideas as to why the file is a different size?

Thanks for any help.

04-15-2012, 09:15 PM
From the looks of your code you're using output buffering. Why then are you using ob_clean to clean the buffer - including those headers you've just created?