HTML create Word *.doc

Discussing Html . Code , Software , other

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 21
Joined: Thu Jul 01, 2004 6:52 am

Wed Sep 01, 2004 4:24 am

I have got button on my page. When user click on a button i want to automaticaly create word document with some content and opens it instanlty. On a user computer ofcourse.

User avatar
Posts: 2257
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Wed Sep 01, 2004 5:54 am

Why is this in the HTML forum? You sure can't do this with HTML.

New php-forum User
New php-forum User
Posts: 6
Joined: Thu Sep 02, 2004 6:06 am
Location: Sydney, Australia

Thu Sep 02, 2004 6:32 am

One way to do this, using PHP and javascript, is to have a page docfile.php which displays the MS Word file in the browser if the user is running IE, or brings up a download dialog for it otherwise.

On the page with the button, get it to use javascript to figure out whether the user is running IE or not, and send that information onto docfile.php via a GET request.

Then, in docfile.php, use a header to set the MIME type.

header("Content-type: application/msword");

Then, if the user is running IE, you can have it viewed in the browser with:

header("Content-Disposition: inline");

or otherwise:

header("Content-Disposition: attachment; filename=$filename");

to have it save to the local computer, where $filename is the name you want it to be saved as.

Then just throw in your content.

Post Reply