php 未找到“COM”类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10678325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class 'COM' not found
提问by Othman
I've been trying to open a word document in my script, but I get receiving the same error.
我一直试图在我的脚本中打开一个 word 文档,但我收到了同样的错误。
Fatal error: Class 'COM' not found in /Applications/XAMPP/xamppfiles/htdocs/**/**.php on line 3
My code:
我的代码:
<?php
$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Visible = 1;
$word->Documents->Open("wordfile.docx");
$temp = $word->Dialogs->Item(228); // returns wdDialogToolsWordCount dialog object
$temp->Execute(); //updates the word count
$numwords = $temp->Words(); //gets the words out of it
echo 'Word count = '.$numwords;
$word->Quit();
?>
I've tried to change php.iniand remove the semicolons from COMsection.
我试图更改php.ini和删除COM部分中的分号。
[com]
path to a file containing GUIDs, IIDs or filenames of files with TypeLibs
com.typelib_file =
allow Distributed-COM calls
com.allow_dcom = true
autoregister constants of a components typlib on com_load()
com.autoregister_typelib = true
register constants casesensitive
com.autoregister_casesensitive = false
show warnings on duplicate constat registrations
com.autoregister_verbose = true
and still getting the same error.
并且仍然收到相同的错误。
I'm using a XAMMPon mac, and a linux based web hosting.
我XAMMP在 mac 上使用一个,以及一个基于 linux 的网络托管。
回答by StXh
From PHP 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini:
从 PHP 5.4.5 开始,PHP 核心不再内置 COM 和 DOTNET。您必须在 php.ini 中添加 COM 支持:
[COM_DOT_NET]
extension=php_com_dotnet.dll
Otherwise you will see this in your error log: Fatal error: Class 'COM' not found
否则,您将在错误日志中看到:致命错误:找不到类“COM”
The extension is included with php 5.4.5 for Windows.
该扩展包含在适用于 Windows 的 php 5.4.5 中。
回答by Othman
See COM Requirements:
请参阅COM 要求:
COM functions are only available for the Windows version of PHP.
.Net support requires PHP 5 and the .Net runtime.
COM 函数仅适用于 Windows 版本的 PHP。
.Net 支持需要 PHP 5 和 .Net 运行时。
回答by GeorgFromTheAlps
Using Windows Server2019, Apache 32Bit (C:\Apache24), PHP 32Bit (C:\PHP)
使用 Windows Server2019、Apache 32Bit (C:\Apache24)、PHP 32Bit (C:\PHP)
As jross wrote: Full path to php_com_dotnet.dll was the solution for me (extension=C:\PHP\ext\php_com_dotnet.dll).
正如 jross 所写: php_com_dotnet.dll 的完整路径是我的解决方案(扩展名 = C:\PHP\ext\php_com_dotnet.dll)。

