Solved

Error when I open a word document at php.

Posted on 2007-04-02
7
446 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now