1

I am having trouble trying to get a pdf to open in the browser for the user. I have searched:

How to display pdf in php

and while it looks like it should work, I simply get Failed to Load PDF Document.

This is my code for the page. There is more html below this, however I am looking to get the functionality working first.

<?php
include "header.html";

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename=FLLVolSignUp.pdf');
@readfile('./Supporting_Files/Downloads/FLLVolSignUp.pdf');
?>

I'm running Google Chrome, Adobe reader, and this is a project for school that I am hosting on a IIS server.

If anyone has some insight into how I could get this working, I would really appreciate it, Thanks!

Community
  • 1
  • 1
Mystified
  • 137
  • 1
  • 9
  • Remove the `@` before that `readfile` command. _Never_ suppress errors, they offer helpful information. Next check your http servers error log file, it will tell you what the issue is. – arkascha Dec 10 '16 at 17:05
  • Also I am wondering what that `include "header.html";` is meant to do. If that inclusion outputs _anything_, then things certainly will not work. the `header()` calls have to be the first thing that atually outputs anything, such is the definition of the http protocol: headers first, _then_ content. – arkascha Dec 10 '16 at 17:06
  • http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Shira Dec 10 '16 at 17:07
  • http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php – Shira Dec 10 '16 at 17:07
  • @arkascha Hey, thanks for replying. I'm not home right now but I'll try that when I get back. How abouts do I go checking my server logs? Also, the header.html is the top part of a template. I'm just trying to get the pdf browsing funtionality down. – Mystified Dec 10 '16 at 19:25
  • You can not embed a PDF document this way. Those headers will only work if the document is send by itself. You cannot have http headers in the middle of a html page. – arkascha Dec 10 '16 at 19:33
  • @arkascha My apologies for the silence. My time away from home was a little more than I expected. I've tried removing the @ from the readfile line and I removed everything else from the file. However, it still can't seem to load the pdf. – Mystified Dec 11 '16 at 17:49
  • @arkascha Nevermind. I figured it out. Thank you so much for your help though! You too ShiraNai7 ! I am going to look into getting errors to display as I didn't even know you could with php. Thanks a lot! Oh, and I'm ashamed to say that my problem was actually with the file path of all things... – Mystified Dec 11 '16 at 18:14
  • All fine, we all make mistakes like that. About error visualizations: learn _not_ to visualize them in the output, but in the error file the http server writes anyway. Much more helpful. – arkascha Dec 11 '16 at 19:07
  • @arkascha Thanks, I'll keep that in mind. I looked at the log that IIS left for me but right now it's a foreign language to me. I'll have to learn to read them after exams are done @_@. – Mystified Dec 11 '16 at 19:11

0 Answers0