473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sending PDF as output

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
8 8673
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
"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
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
"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
"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
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
"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
[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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: praba kar | last post by:
Dear All, I have doubt regarding mail sending smtplib module. The below code is I used to send a mail. ########################################## import email.Message import email.Utils...
4
by: David | last post by:
I'm wondering if python is capable of fairly precise timing and also sending data out the parallel port. For example ; making a 7.5 KHz square wave come out of one of the data pins on the...
4
by: yaron | last post by:
Hi, I have a problem when sending data over TCP socket from c# client to java server. the connection established ok, but i can't send data from c# client to java server. it's work ok with...
4
by: splicemix | last post by:
Hi all, I have recently set up a Drupal website. I am a beginner. My shared host server does not allow nobody@localhost to send emails, and prevents access to php.ini, so I spent some time...
2
by: nautonnier | last post by:
Hello, I have a C# app that spawns several processes each containing a console app written by another developer in C++. The console app was written first to be just like a console app: it...
0
by: duclm | last post by:
Hi all, II am having problem sending zip file(binary file) using webrequest function from wince5.0 device to a webpage. It works fine for any file with size less than or equal to 1.5kb. Any bigger...
9
by: JoeP | last post by:
Hi All, How can I find the reason for such an error: Failure sending mail. Some Code... oMailMessage.IsBodyHtml = False oMailMessage.Body = cEmailBody Dim oSMTP As New SmtpClient...
1
by: Rich | last post by:
Hello, I am working on a python library for sending and receiving data from a Subaru's ECU (the fuel injection computer) via the OBD-II port and an OBD to USB cable, with the Subaru Select Monitor...
0
by: Gabriel Genellina | last post by:
En Fri, 02 May 2008 16:50:46 -0300, Rich <richietommy@yahoo.comescribió: No, chr works as it should. The same thing can be written as ser.write("\x80\x10\xF0\x01\xBF\x40") Are you sure you're...
4
by: George Oliver | last post by:
hi, I'm a novice programmer trying to better define a hobby project I'm thinking of. What I would like to do is take a program and embed it or put it within a Python-run GUI, using the GUI just...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.