By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,036 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,036 IT Pros & Developers. It's quick & easy.

Sending PDF as output

P: n/a
I have a pdf file (syllabus.pdf) on the server. I have written the
following PHP code. It correctly finds the file, but it is sending the file
back as text I think because I'm seeing the binary in the browser rather
than seeing the PDF loaded by Adober Reader. I've done with with Perl, but
I've never tried this with PHP. Can someone point out what I'm doing wrong
and how to fix it so that my PHP script can serve PDFs?

<?php
header("Cache-control: no-store\n");
header("Content-type: application/pdf\n\n");
readfile("$DOCUMENT_ROOT/syllabus.pdf");
?>

Thanks
Jul 17 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover" <no****@goawayspam.com>
wrote:
I have a pdf file (syllabus.pdf) on the server. I have written the
following PHP code. It correctly finds the file, but it is sending the file
back as text I think because I'm seeing the binary in the browser rather
than seeing the PDF loaded by Adober Reader. I've done with with Perl, but
I've never tried this with PHP. Can someone point out what I'm doing wrong
and how to fix it so that my PHP script can serve PDFs?

<?php
header("Cache-control: no-store\n");
Don't end the header lines with \n; PHP handles that in the header() function.
header("Content-type: application/pdf\n\n");
The \n above probably ended the headers so this one isn't being picked up.
readfile("$DOCUMENT_ROOT/syllabus.pdf");


$DOCUMENT_ROOT isn't set by anything in this script.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #2

P: n/a
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:i7********************************@4ax.com...
On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover" <no****@goawayspam.com>
wrote:
I have a pdf file (syllabus.pdf) on the server. I have written the
following PHP code. It correctly finds the file, but it is sending the fileback as text I think because I'm seeing the binary in the browser rather
than seeing the PDF loaded by Adober Reader. I've done with with Perl, butI've never tried this with PHP. Can someone point out what I'm doing wrongand how to fix it so that my PHP script can serve PDFs?

<?php
header("Cache-control: no-store\n");
Don't end the header lines with \n; PHP handles that in the header()

function.
header("Content-type: application/pdf\n\n");
The \n above probably ended the headers so this one isn't being picked

up.
readfile("$DOCUMENT_ROOT/syllabus.pdf");


$DOCUMENT_ROOT isn't set by anything in this script.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)


Thanks. I made the following changes and still no luck. I have confirmed
that the script is indeed finding the file though.

<?php
header("Cache-control: no-store");
header("Content-type: application/pdf");
header("Content-Disposition: inline, filename=syllabus.pdf");
$filename = '/public_html/syllabus.pdf';
readfile($filename);
?>
Jul 17 '05 #3

P: n/a
Kubaton Lover wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:i7********************************@4ax.com...
On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover" <no****@goawayspam.com>
wrote:

I have a pdf file (syllabus.pdf) on the server. I have written the
following PHP code. It correctly finds the file, but it is sending the
file
back as text I think because I'm seeing the binary in the browser rather
than seeing the PDF loaded by Adober Reader. I've done with with Perl,
but
I've never tried this with PHP. Can someone point out what I'm doing
wrong
and how to fix it so that my PHP script can serve PDFs?

<?php
header("Cache-control: no-store\n");


Don't end the header lines with \n; PHP handles that in the header()


function.
header("Content-type: application/pdf\n\n");


The \n above probably ended the headers so this one isn't being picked


up.
readfile("$DOCUMENT_ROOT/syllabus.pdf");


$DOCUMENT_ROOT isn't set by anything in this script.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

Thanks. I made the following changes and still no luck. I have confirmed
that the script is indeed finding the file though.

<?php
header("Cache-control: no-store");
header("Content-type: application/pdf");
header("Content-Disposition: inline, filename=syllabus.pdf");
$filename = '/public_html/syllabus.pdf';
readfile($filename);
?>


Are you by any chance using Internet Exploder?

IE often ignores mime types in favour of file extensions. I suggest you
link to this php script as follows:
<a href="http://www.server.com/script.php/syllabus.pdf">xxx</a>

The trailing 'syllabus.pdf' might just make IE behave.

Jul 17 '05 #4

P: n/a
"Kevin Thorpe" <ke***@pricetrak.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Kubaton Lover wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:i7********************************@4ax.com...
On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover" <no****@goawayspam.com>wrote:
I have a pdf file (syllabus.pdf) on the server. I have written the
following PHP code. It correctly finds the file, but it is sending the


file
back as text I think because I'm seeing the binary in the browser ratherthan seeing the PDF loaded by Adober Reader. I've done with with Perl,


but
I've never tried this with PHP. Can someone point out what I'm doing


wrong
and how to fix it so that my PHP script can serve PDFs?

<?php
header("Cache-control: no-store\n");

Don't end the header lines with \n; PHP handles that in the header()


function.
header("Content-type: application/pdf\n\n");

The \n above probably ended the headers so this one isn't being picked


up.
readfile("$DOCUMENT_ROOT/syllabus.pdf");

$DOCUMENT_ROOT isn't set by anything in this script.

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

Thanks. I made the following changes and still no luck. I have confirmed that the script is indeed finding the file though.

<?php
header("Cache-control: no-store");
header("Content-type: application/pdf");
header("Content-Disposition: inline, filename=syllabus.pdf");
$filename = '/public_html/syllabus.pdf';
readfile($filename);
?>


Are you by any chance using Internet Exploder?

IE often ignores mime types in favour of file extensions. I suggest you
link to this php script as follows:
<a href="http://www.server.com/script.php/syllabus.pdf">xxx</a>

The trailing 'syllabus.pdf' might just make IE behave.


You are correct, I am using IE. When I add /syllabus.pdf to the url, it
prompts me to Open or Save the file which is unusual since other PDF files
(accessed directly) do not do that. If I click "Open", it behaves as if it
is downloading the pdf, but then returns the following error:

"Internet Explorer cannot download syllabus.pdf from www.yourdomain.com.
Internet Explorer was not able to open this Internet site. The requested
site is either unavailable or cannot be found. Please try again later."
Jul 17 '05 #5

P: n/a
"Kubaton Lover" <no****@goawayspam.com> wrote in message news:<vq************@corp.supernews.com>...
"Kevin Thorpe" <ke***@pricetrak.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
Kubaton Lover wrote:
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:i7********************************@4ax.com...
You are correct, I am using IE. When I add /syllabus.pdf to the url, it
prompts me to Open or Save the file which is unusual since other PDF files
(accessed directly) do not do that. If I click "Open", it behaves as if it
is downloading the pdf, but then returns the following error:


Read the user notes at http://in2.php.net/header and see if it is
solves your problem.

---
"Learn from yesterday, live for today, hope for tomorrow. The
important thing is to not stop questioning."---Albert Einstein
Email: rrjanbiah-at-Y!com
Jul 17 '05 #6

P: n/a
Are you by any chance using Internet Exploder?

IE often ignores mime types in favour of file extensions. I suggest you
link to this php script as follows:
<a href="http://www.server.com/script.php/syllabus.pdf">xxx</a>

The trailing 'syllabus.pdf' might just make IE behave.

You are correct, I am using IE. When I add /syllabus.pdf to the url, it
prompts me to Open or Save the file which is unusual since other PDF files
(accessed directly) do not do that. If I click "Open", it behaves as if it
is downloading the pdf, but then returns the following error:

"Internet Explorer cannot download syllabus.pdf from www.yourdomain.com.
Internet Explorer was not able to open this Internet site. The requested
site is either unavailable or cannot be found. Please try again later."

Your problem there is probably the 'Cache-Control: no-store'. Other
browsers handle things differently, but IE executes an external
application and gives it the filename in cache. If the document isn't
cached then Acrobat can't have the document. Unfortunately IE is
fundamentally broken in handling these things.

Jul 17 '05 #7

P: n/a
"Kevin Thorpe" <ke***@pricetrak.com> wrote in message
news:3f**********************@news.easynet.co.uk.. .
Are you by any chance using Internet Exploder?

IE often ignores mime types in favour of file extensions. I suggest you
link to this php script as follows:
<a href="http://www.server.com/script.php/syllabus.pdf">xxx</a>

The trailing 'syllabus.pdf' might just make IE behave.

You are correct, I am using IE. When I add /syllabus.pdf to the url, it
prompts me to Open or Save the file which is unusual since other PDF files (accessed directly) do not do that. If I click "Open", it behaves as if it is downloading the pdf, but then returns the following error:

"Internet Explorer cannot download syllabus.pdf from www.yourdomain.com.
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."

Your problem there is probably the 'Cache-Control: no-store'. Other
browsers handle things differently, but IE executes an external
application and gives it the filename in cache. If the document isn't
cached then Acrobat can't have the document. Unfortunately IE is
fundamentally broken in handling these things.

Thanks, but I...
A. am successfully using no-store with a Perl script.
B. have tried taking out the cache-control with no improvement.
Jul 17 '05 #8

P: n/a
[snipped]

Looks like my main problem is caching in IE6. I was using 2 different
machines and I was trying to set the cache to "no-store" or "no-cache", but
it was still being cached. After clearing the cache and rebooting one of
the machines, the code seems to work.

I HATE THAT KIND OF B.S.!

Thanks for all your help.
Jul 17 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.