简体   繁体   English

如何命令PHP在PC上打开MS Word并打开PC上的MS Word文件

[英]How to command PHP to open MS Word on PC and open the MS Word file on it

Basically, what I'm trying to do is to make a little script on PHP through which when the user clicks on "View File", the MS Word application on the client's computer should open automatically if it exists, and display/open the document file that is on the server.基本上,我想做的是在 PHP 上制作一个小脚本,当用户点击“查看文件”时,客户端计算机上的 MS Word 应用程序应该自动打开(如果存在),并显示/打开文档服务器上的文件。 I have tried using exec() and COM but they both don't seem to work properly.我试过使用 exec() 和 COM 但它们似乎都不能正常工作。 Here is the code I'm using to open MS Word.这是我用来打开 MS Word 的代码。

com_load_typelib('Word.Application');
$word = new COM("word.application");
$docName='C:/xampp/htdocs/phpword/helloWorld.docx';
$word->Documents->Open($docName);

This is the code I'm using to open the file.这是我用来打开文件的代码。

Fatal error: Uncaught Error: Class 'COM' not found in C:\xampp\htdocs\phpword\word.php:16 Stack trace: #0 {main} thrown in C:\xampp\htdocs\phpword\word.php on line 16致命错误:未捕获错误:Class 在 C 中未找到“COM”:\xampp\htdocs\phpword\word.php:16 堆栈跟踪:#0 {main} 在 C:\xampp\htdocs\phpword\word.8555328 on.8819453 中抛出第 16 行

This is the error I get.这是我得到的错误。

You cannot control the client's computer from your PHP server.您无法从您的 PHP 服务器控制客户的计算机。 exec() for example will execute a program on your PHP server, but you cannot run programs, open files etc on the client's computer.例如, exec()将在您的 PHP 服务器上执行一个程序,但您不能在客户端计算机上运行程序、打开文件等。 That is a hacker's job:)那是黑客的工作:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM