사용자가 양식을 성공적으로 제출하면 PDF 파일을 다운로드 할 수있게하려고합니다.PHP : PDF 파일을 다운로드 가능하게하려고 시도합니다.
나는 this question의 코드를 사용했으나 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()
여기에 사용중인 코드가 표시됩니다. – Cfreak
콘텐츠 유형 헤더를 보내거나 잘못 보내는 것을 잊어 버린 것처럼 보입니다. 예를 들어,'header ("Content-Type : application/octet-stream");'코드를 보여줄 수 있습니까? 특히 파일 상단과'header (...)'호출 사이에 모든 행 (공백)을 표시하는 것이 중요합니다. – jedwards
이미 출력 되었기 때문에 귀하의 헤더를 보낼 수 없다고 생각합니다 ... 그리고 역시 PDF 후에 HTML을 볼 수 있습니까? – Wrikken