Jump to content

Recommended Posts

Hello,

 

I am using the COM function in PHP to open and create word documents locally on my intranet server here. It works great when you use it on the host system but when you use it on another machine locally that isnt the host it worked fine, but it opens the word document on the host machine rather than the client machine.

 

Can anyone help as to how to open the word document on the client machine?

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/
Share on other sites

<?php
// starting word
$word = new COM("word.application") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;
?>

This may be useful for you.

You can't open a Word document on a client (i.e. web user's) machine. Imagine the havoc one could cause. So unless i'm misunderstanding your request, it can't be done.

What you can do is open the word file on the server (host machine) put your text into it, then serve it up to the client for download...

Hi,

 

Yes that is what i would like to do, the client machine has word, but it seems the word visible function opens it on the host machine rather than the client machine, is their a way to show the word file it has just opened on the client machine rather than loading it up on the host machine?

 

Thanks for your help.

Create the file on host machine as "test.doc" and send to the browser using

 

<?php
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers 
header("Content-Type: application/msword");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename("test.doc")."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("test.doc"));
readfile("test.doc");
exit();
?>

Thank you for the code.

 

That works and sends the document to the browser correctly.

 

The only issue is that it doesnt open the actual file on the local server it sends it to the browser instead.

 

Is their a way of doing the above, but when it is send to the client it is using the version on the host machine rather than caching it on the clients machine.

 

Thanks very much though i am much further than where i was

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.