I'm trying to make a PDF file downloadable after user submits a form successfully.
I have used the code from this question, but the content of the pdf file gets outputted as gebrish characters instead of the download dialog to popup.
The download code is called from within a function
function phpfmg_thankyou(){
phpfmg_redirect_js();
//include('get_file.php');
$pdf_file = "{$_SERVER['DOCUMENT_ROOT']}/secured_assets/CRE_White_Paper_Release_01-15-2013.pdf";
if( file_exists( $pdf_file ) ){
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . Urlencode('CRE_White_Paper_Release_01-15-2013.pdf'));
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
header("Content-Length: " . Filesize($pdf_file));
flush(); // this doesn't really matter.
$fp = fopen($pdf_file, "r");
while (!feof($fp)){
echo fread($fp, 65536);
flush(); // this is essential for large downloads
}
fclose($fp);
}
?>
<!-- [Your confirmation message goes here] -->
<br>
<div style="padding: 1em; background: #CDD7B6;">
<b>Your inquiry has been received. Thank you!</b>
<p><a title="FREE White Paper Commercial Real Estate Expectations" href="secured_assets/CRE_White_Paper_Release_01-15-2013.pdf">Click Here</a> to get your FREE copy of White Paper Commercial Real Estate Expectations</p>
</div>
<?php
} // end of function phpfmg_thankyou()