Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

php - Class 'COM' not found

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...