Solved

Error when I open a word document at php.

Posted on 2007-04-02
7
452 Views
Last Modified: 2013-12-13
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
Comment
Question by:znotte
  • 2
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
NickVd earned 250 total points
ID: 18839020
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
 

Author Comment

by:znotte
ID: 18839228
Thanks a lot NickVd!

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

Thank you!
0
 
LVL 29

Assisted Solution

by:rdivilbiss
rdivilbiss earned 250 total points
ID: 18839812
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
 

Author Comment

by:znotte
ID: 18839839
Hi rdivilbiss,

I tried header( "Content-Disposition: attachment; filename=file.doc"); and the error is sitll there
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 18839925
Nothing is being written to the client prior?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question