Connecting Tech Pros Worldwide Forums | Help | Site Map

Sending PDF as output

Kubaton Lover
Guest
 
Posts: n/a
#1: Jul 17 '05
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



Andy Hassall
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Sending PDF as output


On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover" <nospam@goawayspam.com>
wrote:
[color=blue]
>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");[/color]

Don't end the header lines with \n; PHP handles that in the header() function.
[color=blue]
>header("Content-type: application/pdf\n\n");[/color]

The \n above probably ended the headers so this one isn't being picked up.
[color=blue]
>readfile("$DOCUMENT_ROOT/syllabus.pdf");[/color]

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

--
Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Kubaton Lover
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Sending PDF as output


"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:i7hnqvk3ac9g8hv1oe8o6nfdkk6kseqt9p@4ax.com...[color=blue]
> On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover" <nospam@goawayspam.com>
> wrote:
>[color=green]
> >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[/color][/color]
file[color=blue][color=green]
> >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,[/color][/color]
but[color=blue][color=green]
> >I've never tried this with PHP. Can someone point out what I'm doing[/color][/color]
wrong[color=blue][color=green]
> >and how to fix it so that my PHP script can serve PDFs?
> >
> ><?php
> >header("Cache-control: no-store\n");[/color]
>
> Don't end the header lines with \n; PHP handles that in the header()[/color]
function.[color=blue]
>[color=green]
> >header("Content-type: application/pdf\n\n");[/color]
>
> The \n above probably ended the headers so this one isn't being picked[/color]
up.[color=blue]
>[color=green]
> >readfile("$DOCUMENT_ROOT/syllabus.pdf");[/color]
>
> $DOCUMENT_ROOT isn't set by anything in this script.
>
> --
> Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
> Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]

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);
?>


Kevin Thorpe
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Sending PDF as output


Kubaton Lover wrote:[color=blue]
> "Andy Hassall" <andy@andyh.co.uk> wrote in message
> news:i7hnqvk3ac9g8hv1oe8o6nfdkk6kseqt9p@4ax.com...
>[color=green]
>>On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover" <nospam@goawayspam.com>
>>wrote:
>>
>>[color=darkred]
>>>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[/color][/color]
>
> file
>[color=green][color=darkred]
>>>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,[/color][/color]
>
> but
>[color=green][color=darkred]
>>>I've never tried this with PHP. Can someone point out what I'm doing[/color][/color]
>
> wrong
>[color=green][color=darkred]
>>>and how to fix it so that my PHP script can serve PDFs?
>>>
>>><?php
>>>header("Cache-control: no-store\n");[/color]
>>
>> Don't end the header lines with \n; PHP handles that in the header()[/color]
>
> function.
>[color=green][color=darkred]
>>>header("Content-type: application/pdf\n\n");[/color]
>>
>> The \n above probably ended the headers so this one isn't being picked[/color]
>
> up.
>[color=green][color=darkred]
>>>readfile("$DOCUMENT_ROOT/syllabus.pdf");[/color]
>>
>> $DOCUMENT_ROOT isn't set by anything in this script.
>>
>>--
>>Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
>>Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]
>
>
> 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);
> ?>[/color]

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.

Kubaton Lover
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Sending PDF as output


"Kevin Thorpe" <kevin@pricetrak.com> wrote in message
news:3fabc94a$0$27619$afc38c87@news.easynet.co.uk. ..[color=blue]
> Kubaton Lover wrote:[color=green]
> > "Andy Hassall" <andy@andyh.co.uk> wrote in message
> > news:i7hnqvk3ac9g8hv1oe8o6nfdkk6kseqt9p@4ax.com...
> >[color=darkred]
> >>On Fri, 7 Nov 2003 10:06:25 -0600, "Kubaton Lover"[/color][/color][/color]
<nospam@goawayspam.com>[color=blue][color=green][color=darkred]
> >>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[/color]
> >
> > file
> >[color=darkred]
> >>>back as text I think because I'm seeing the binary in the browser[/color][/color][/color]
rather[color=blue][color=green][color=darkred]
> >>>than seeing the PDF loaded by Adober Reader. I've done with with Perl,[/color]
> >
> > but
> >[color=darkred]
> >>>I've never tried this with PHP. Can someone point out what I'm doing[/color]
> >
> > wrong
> >[color=darkred]
> >>>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()[/color]
> >
> > function.
> >[color=darkred]
> >>>header("Content-type: application/pdf\n\n");
> >>
> >> The \n above probably ended the headers so this one isn't being picked[/color]
> >
> > up.
> >[color=darkred]
> >>>readfile("$DOCUMENT_ROOT/syllabus.pdf");
> >>
> >> $DOCUMENT_ROOT isn't set by anything in this script.
> >>
> >>--
> >>Andy Hassall (andy@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
> >>Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)[/color]
> >
> >
> > Thanks. I made the following changes and still no luck. I have[/color][/color]
confirmed[color=blue][color=green]
> > 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);
> > ?>[/color]
>
> 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.[/color]

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."


R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Sending PDF as output


"Kubaton Lover" <nospam@goawayspam.com> wrote in message news:<vqnnk76a03njdf@corp.supernews.com>...[color=blue]
> "Kevin Thorpe" <kevin@pricetrak.com> wrote in message
> news:3fabc94a$0$27619$afc38c87@news.easynet.co.uk. ..[color=green]
> > Kubaton Lover wrote:[color=darkred]
> > > "Andy Hassall" <andy@andyh.co.uk> wrote in message
> > > news:i7hnqvk3ac9g8hv1oe8o6nfdkk6kseqt9p@4ax.com...[/color][/color][/color]
[color=blue]
> 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:[/color]

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
Kevin Thorpe
Guest
 
Posts: n/a
#7: Jul 17 '05

re: Sending PDF as output


[color=blue][color=green]
>>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.[/color]
>
>
> 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."
>
>[/color]
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.

Kubaton Lover
Guest
 
Posts: n/a
#8: Jul 17 '05

re: Sending PDF as output


"Kevin Thorpe" <kevin@pricetrak.com> wrote in message
news:3faf669e$0$2124$afc38c87@news.easynet.co.uk.. .[color=blue]
>[color=green][color=darkred]
> >>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.[/color]
> >
> >
> > 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[/color][/color]
files[color=blue][color=green]
> > (accessed directly) do not do that. If I click "Open", it behaves as if[/color][/color]
it[color=blue][color=green]
> > 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[/color][/color]
requested[color=blue][color=green]
> > site is either unavailable or cannot be found. Please try again later."
> >
> >[/color]
> 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.[/color]


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


Kubaton Lover
Guest
 
Posts: n/a
#9: Jul 17 '05

re: Sending PDF as output


[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.


Closed Thread