web2000 Posted January 22, 2008 Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/ Share on other sites More sharing options...
web2000 Posted January 22, 2008 Author Share Posted January 22, 2008 Here is the code $word = new COM("word.application") or die("Unable to instantiate Word"); $template_file = "C:/Webspace/landlordletter.doc"; $word->Documents->Open($template_file); $word->Documents[1]->SaveAs($doc); $word->visible = 1; Quote Link to comment https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/#findComment-446022 Share on other sites More sharing options...
pdkv2 Posted January 22, 2008 Share Posted January 22, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/#findComment-446030 Share on other sites More sharing options...
aschk Posted January 22, 2008 Share Posted January 22, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/#findComment-446035 Share on other sites More sharing options...
web2000 Posted January 22, 2008 Author Share Posted January 22, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/#findComment-446036 Share on other sites More sharing options...
pdkv2 Posted January 22, 2008 Share Posted January 22, 2008 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/#findComment-446040 Share on other sites More sharing options...
web2000 Posted January 22, 2008 Author Share Posted January 22, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/87203-php-new-comwordapplication-help-please/#findComment-446050 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.