• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

Error when I open a word document at php.

Hello everybody,

I'm having this following problem.

I have a button inside an ajax page in PHP code that opens a word document. When I use Firefox, this download works but when I use Internet Explorer it doesn't work and appears this message:

"Internet Explorer was not able to open this Internet site. The requested site is either unavaiable or cannto be found. Please try again later."

After all the queries at the page, I have this header:

header( "Content-type: application/ms-word" );
header( "Content-Disposition: attachment; filename=file.rtf");

Is there anyone that can help me?

Thanks!
0
znotte
Asked:
znotte
  • 2
  • 2
2 Solutions
 
NickVdCommented:
I can help :)

I came across this precise problem a couple days ago when I wrote a coupon generator that spits out PDF based coupons.  It works perfectly in ff but i got the exact error in ie.

My solution was to use a rewrite rule to trick IE into thinking that the url is a file, when it's being re-written into a dynamic url as in index.php?couponid=20

So, http://example.com/coupon25.pdf would look like a standard pdf file to IE, but apache would rewrite it to look like

http://example.com/genCoupon.php?couponID=20 which would spit out the pdf file set the headers etc.

I got the idea from the FAQ page of the pdf library I was using (FPDF -- Highly recommended!), it also outlines a couple different solutions to the problem.  The easiest is to generate the document temporarily and redirect the browser to the file, that way they're simply downloading a file, rather streaming it from the php script.

http://fpdf.org/en/FAQ.php#3

Hope this solves your problem, or at least points you in the right direction!
0
 
znotteAuthor Commented:
Thanks a lot NickVd!

I'll try this than I'll get back to you!

Thank you!
0
 
rdivilbissCommented:
As far as IE is concerned, it depends on the local computer's MIME type assignments.  In the good old days IE was a bit promiscuous as to what it would accept and that was tightened.

Just for simplicities sake, try header( "Content-Disposition: attachment; filename=file.doc");

When you say application/msword and send a doc file all should be fine, but even though MS Word can open an rtf file, it may not be the associated extension for the MIME type application/msword in IE.

0
 
znotteAuthor Commented:
Hi rdivilbiss,

I tried header( "Content-Disposition: attachment; filename=file.doc"); and the error is sitll there
0
 
rdivilbissCommented:
Nothing is being written to the client prior?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now