Solved

Error when I open a word document at php.

Posted on 2007-04-02
7
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 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