用户成功提交表单后,我正在尝试使 PDF 文件可下载。
我已经使用了这个问题的代码,但是 pdf 文件的内容被输出为 gebrish 字符,而不是弹出的下载对话框。
从函数中调用下载代码
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()