TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > PHP

Notices

php, Adobe and IE getting things wrong again.

PHP


Reply
 
Thread Tools Display Modes
Old 02-12-2007, 04:49 AM   #1
Ian Hobson
Guest
 
Posts: n/a
php, Adobe and IE getting things wrong again.

Hi All,

I have a web app written in php, that generates a pdf file on the fly.

I think I need to kill the headers that php is automatically generating,
and I don't know how to do it.

The basic idea is that the href in the anchor is to a URL of the form



This is processed by modrewrite into

/sop/index.php?view=quote&id=27&act=print

The code creates the .pdf, prepends a

header('Content-Disposition',"inline; filename="quote27.pdf"');

and sends it back. The browser then uses adobe acrobat to display the
result. Using standard adobe plugins the resulting file can be printed
or emailed - all very user friendly etc.

Everything works absolutely fine under Firefox - no errors, no warnings,
just the desired results.

But when I try it with IE, I get

"There was an error opening this document. The file cannot be found"

Googling the error message gives 3 pages of results. Although I found
lots to try, nothing has worked so far.

I have tried...

Cache-Control Pivate and Public - neither made any difference.
Checked the security of the site is "medium" or "permitted", and that
"software channel" and "Launch program in Iframe" are permitted - They are.
Ive deleted all off-line content, and the index.dat file and rebooted,
to remove errors in the cache.
I have been advised to avoid Unicode characters in external links -
there are no links, internal or external.
Add a Content-Tranfer-Encoding" header with value Binary - made no
difference.

I tried various combinations of Content-Disposition header. If it was
"inline", "attachment" Firefax worked and IE/Adobe complained it could
not find the file.

If I modified the Adobe Edit/Options/Internet and cleared the "Show PDF
in browser (and rebooted), then IE complains that it can't download
<file> from <site>.

"Internet Explorer was not able to open this Internet site. The
requested site is either unavailable or cannot be found. Please try
later." The site is served by Apache running as a service on the same
machine as the browser - and no it has not gone down. Doing the same in
FireFox saves the file (unprompted) to file.pdf (not quote27.pdf).

After MUCH testing and debugging I have discovered that php has the
following headers *already* set up to go before I start adding mine.

array(4) {
[0]=>
string(23) "X-Powered-By: PHP/5.2.3"
[1]=>
string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT"
[2]=>
string(77) "Cache-Control: no-store, no-cache, must-revalidate,
post-check=0, pre-check=0"
[3]=>
string(16) "Pragma: no-cache"
}

This is usually fine for a php file, but its not what I want for these
..pdf files, and I suspect they are stopping IE store the file in the
cache, which is why Adobe can't find it! I can't find any quote27.pdf
files either.

How can I remove these headers?

Ans how can I have a look at the headers that are actually sent? I tries
wireshark, but the http never gets onto a wire, so wireshark can't grab
it!

All help gratefully received.

Ian

Environment - Apache 2.0, php 5. Adobe Acrobat 8.1.1
Firefox 2, IE6 under window 2000 SP4.

Target - IE7 under a mix of Vista and XP machines.




  Reply With Quote
Old 02-12-2007, 06:48 PM   #2
Ian Hobson
Guest
 
Posts: n/a
Re: php, Adobe and IE getting things wrong again.

To follow up my own post...

I've cracked it.

It appears that

1) PHP sends various "do not cache" headers as standard.

2) Browsers who receive content for display in another application store
the file and pass the filename to the application for display.

Except for IE 6 and 7.

These sees the "no cache" headers and do NOT store the file, yet they
still pass the filename to Adobe Acrobat for display. Go figure!

The solution is to replace all the headers the system generates with "do
cache" versions. The crucial frament of code is now...

header('Content-Disposition: inline; filename="quote27.pdf"');
header('Content-type: application/pdf');
header('Cache-Control: maxage=120');
header('Expires: '.date(DATE_COOKIE,time()+120)); // Cache for 2 mins
header('Pragma: public');

Lets hope that 120 seconds is long enough for IE to see it as future,
even when the clocks are a bit wrong, and short enough that the user has
not the time to see an error, fix it and call for a reprint!

Hope that helps someone....

Regards

Ian
  Reply With Quote
Reply

Thread Tools
Display Modes



< Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT +5.5. The time now is 04:50 PM.


vBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2009, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional