Jump to content

Code to force a windows comp to use MSWORD to open a doc


Recommended Posts

I've got a webpage that has a downloadable .doc with some VBA code in it.  When the link is clicked, the user's browser tries to open the doc file embedded in the browser, fails because of the VBA code, and then opens the file in MSWord.  I would like to make this process more seamless and have come to understand that there a combination of html code and php code that will can force the user's local computer open the server saved word document using MS Word.

 

I originally used this code from another forum but was unable to get it to work.  I substituted my server file link in the html code as the target.  Now, when the link is clicked, the php file is opened up as a txt file within the browser.

 

Any help would be appriciated.

 

create a downloadword.php file

 

 

<?

if($_GET["dwn"]) {

 

  // ob_clean(); // emptying the buffer (v >= 4.2)

 

  // Dialog for the download

  header("content-type: application/octet-stream");

  // only for application type:  application/octet-stream !

  header("Content-Disposition: attachment; filename=".$_GET["dwn"]);

 

  // open with MSWord

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

  // open with MSExcel

  // header("content-type: application/vnd.ms-excel");

  // open with text

  // header("content-type: text/plain");

 

  flush(); // send the buffer

 

  readfile($_GET["dwn"]); // send the file

 

}?>

 

 

Check or Uncheck the commented lines, depending on what type of file you use. (word, excel, or other)

 

 

In your HTML file :

 

  <A href="downloadword.php?dwn=yourfile.doc">Test</A>

 

 

Change yourfile.word with the correct file.

// Dialog for the download
   header("content-type: application/octet-stream");

   // open with MSWord
   header("content-type: application/msword");
   // open with MSExcel
   // header("content-type: application/vnd.ms-excel");
   // open with text
   // header("content-type: text/plain");

 

This basically replaces content-type with: application/octet-stream then rechanges it to application/msword until it finally ends up with text/plain. You can only define one content-type

This basically replaces content-type with: application/octet-stream then rechanges it to application/msword until it finally ends up with text/plain. You can only define one content-type

 

Probably a piece of code given as an example somewhere else ;)

 

Anyway,  wintersilke if you do have PHP available, first try changing <? to <?php and see if the script runs this time instead of being downloaded.

It is not working...and yes it was a piece of code that I copied from elsewhere that was suppose to do what I wanted to happen....

 

Its very odd....this html code is basically downloading the php code and displaying it as plain text in the browser...

 

href=3D"http://............/downloadword.=

php?dwn=3D\\myserver\...............\Con=

ductivity_Request.doc">Online=20

                        Request Form;</A><A=20

 

Forgive me if I do not display the entire addresses.  I realize that anyone can see what I write here.

 

Does anyone see anything wrong with what I have here?

 

 

I just learned that if you are prompted to download the php file, that means that php is not running on that server so this solution to my problem is not going to work at the moment.

 

I guess that means a java solution of some sort.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.