Cyjm1120 Posted November 21, 2014 Share Posted November 21, 2014 I have searched for the solution for so long and I still could not solve my problem. I have a localhost server where it stored some pdf files for download. I implemented the following function to force the download: if(isset($_POST['dlPDF'])) { $file = $_SERVER['DOCUMENT_ROOT'] .'/Upload/'.$pdfName; header("Content-Type: application/pdf"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$pdfName"); header("Content-Transfer-Encoding: binary"); // read the file from disk readfile($file); } However I could not open the pdf file properly since it says "the pdf file is not correctly encoded". FYI, the downloaded pdf file is always a few Kb larger than the original file. Please kindly let me know if there is anything I can do to make the pdf readable and I appreciate your help. Quote Link to comment https://forums.phpfreaks.com/topic/292625-pdf-file-not-correctly-encoded-when-downloading-a-pdf-file-from-php/ Share on other sites More sharing options...
requinix Posted November 22, 2014 Share Posted November 22, 2014 How did you upload the files in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/292625-pdf-file-not-correctly-encoded-when-downloading-a-pdf-file-from-php/#findComment-1497272 Share on other sites More sharing options...
mac_gyver Posted November 22, 2014 Share Posted November 22, 2014 i would open the downloaded pdf file using your programming editor to see what it has extra in it (look at both the start and end of the content in the file.) you either have php error message(s) or some text content from your download code file. also, where are you setting $pdfName at in your code? and, AFAIK, the filename='...' attribute value in the attachment; header should have quotes around the actual file name to get all browser types to recognize the file name. Quote Link to comment https://forums.phpfreaks.com/topic/292625-pdf-file-not-correctly-encoded-when-downloading-a-pdf-file-from-php/#findComment-1497329 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.