42

I've been trying to open a word document in my script, but I get receiving the same error.

 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.ini and remove the semicolons from COM section.

[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 XAMMP on mac, and a linux based web hosting.

Othman
  • 2,942
  • 3
  • 22
  • 31

4 Answers4

160

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:

[COM_DOT_NET]
extension=php_com_dotnet.dll

Otherwise you will see this in your error log: Fatal error: Class 'COM' not found

The extension is included with php 5.4.5 for Windows.

vicenteherrera
  • 1,442
  • 17
  • 20
StXh
  • 1,856
  • 1
  • 13
  • 16
  • 1
    *Note* on Windows 8.1 / II 8.5 / 64bit. (Manual FastCGI install of php-5.5.16-nts-Win32-VC11-x64.zip under C:\Php64) I had to use the full path in the php.ini file. extension=C:\Php64\ext\php_com_dotnet.dll -- I did NOT use the [COM_DOT_NET] section just added it at the end of the list of extensions. – jross Aug 24 '14 at 23:48
  • is that valid also for xampp mac os? I've tried but no result – AITAALI_ABDERRAHMANE Dec 01 '14 at 15:49
  • Not sure if you'll receive this message, but I asked this question: https://stackoverflow.com/questions/48994237/php-and-adodb-connection-fail - But I am still receiving the error. I hope you won't mind taking a look. – John Beasley Feb 27 '18 at 20:31
7

See COM Requirements:

COM functions are only available for the Windows version of PHP.

.Net support requires PHP 5 and the .Net runtime.

Community
  • 1
  • 1
1

I'm using PHP version 5.6.14 for one of my projects, the php_com_dotnet.dll file is included in the ext/ directory but the same is not added in the php.ini file. So, you need to add the "extension=php_com_dotnet.dll" line in the php.ini file. Check phpinfo() in the browser to make sure that it is enabled. Hope, this might help someone.

-1

Using 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).