sab Posted April 15, 2015 Posted April 15, 2015 (edited) Hi, I am trying to display PDF pages on different parts of my webpage I am creating. Failed to load PDF file ********************************************************************************************** on my showPDF template, i have: $filePdf = $page->showPdf->filename; on my main.inc: if($filePdf){ header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="' . $filePdf . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($filePdf)); header('Accept-Ranges: bytes'); @readfile($filePdf); $filePdf=''; } else{ echo $content; } ********************************************************************************************** I must be definitely doing something wrong! Edited April 16, 2015 by arvixeuser please use the code block
horst Posted April 15, 2015 Posted April 15, 2015 (edited) you can check on your main.inc if there is a valid filename in $filePdf, if it exists: if (file_exists($filePdf)) { ... } else { echo $content; } BUt currently for debugging purposes you temporarily should do this: if (file_exists($filePdf)) { ... } else { //echo $content; echo "<pre>"; var_dump($filePdf); echo "</pre>"; } this way you can get information what it is what you have assigned to $filePdf. Edited April 15, 2015 by horst
sab Posted April 15, 2015 Author Posted April 15, 2015 I checked as you said and the file exists. It loads. And then it says "Failed to load PDF file".
horst Posted April 15, 2015 Posted April 15, 2015 Maybe you have had output before that line? What does it say trying this: if (headers_sent()) { $filename = $linenum = null; headers_sent($filename, $linenum); echo "<p>read on <a href='http://php.net/manual/en/function.headers-sent.php' target='_blank'>here</a>!</p>"; exit(1); } if (file_exists($filePdf)) { ... } else { echo $content; }
Soma Posted April 15, 2015 Posted April 15, 2015 Actually both don't work for me. And apart from that an 28MB PDF here?. What's that good for?
sab Posted April 15, 2015 Author Posted April 15, 2015 that's a file i can't change the content but still supposed to be there although the size is big. i followed the instructions from suggestion or two from older forum posts. and not sure what i'm doing wrong. i need to display many pdf files on the website. i hope you guys have more suggestions.
horst Posted April 15, 2015 Posted April 15, 2015 // maybe a link to the PDF is enough echo "<a href='{$page->showPdf->url}' target='_blank'> download a nice PDF here </a>"; 3
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now