Solved

Error when I open a word document at php.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to count occurrences of each item in an array.

776 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