2013-04-02 33 views
0

話我使用的COM類的PHP用於計算在MS Word文件中的單詞數。它在我的本地運行良好。但是,當我在服務器上運行它比它給人的錯誤。我想算在MS Word文件

致命錯誤:類「COM」在/home/classics/public_html/filecount/index.php沒有發現線路33

雖然我不包括在當地也COM類,我還沒有這種類型的我只是使用它就像那樣:

<?php 
    if(isset($_POST['submit'])){ 
     $file = $_FILES['docfile']['name']; 
     $file = str_replace(" ","_",$file); 
     $ranname = mt_rand(100,10000); 

     //$file = file_get_contents($file); 
     $ext = pathinfo($file, PATHINFO_EXTENSION); 
     $target ="uploads/"; 
     if(!is_dir($target)) 
     { 
     mkdir($target, 0755); 
     } 

     move_uploaded_file($_FILES['docfile']['tmp_name'],$target.$ranname.".docx"); 
     if($ext == "doc" || $ext == "docx"){ 
$word = new COM("word.application") or die("Unable to instantiate Word"); 

$word->Visible = 1; 


$word->Documents->Open("/filecount/".$target.$ranname.".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(); 
//unlink("uploads/".$file); 
     } 

    } 



?> 

它讓我在本地計數。但在服務器上,它會給出錯誤。請幫我,我會做什麼?

+0

你不'include' COM類;它要麼編譯到PHP中,要麼不是;你的服務器上的COM擴展'enabled'也是如此? –

回答

0

你確定你的服務器上該組件(「word.application」)的存在,並納入到你的PHP文件?

+0

我不知道究竟一個Word.Application做什麼。你能解釋一下嗎? – user2226181

+0

word.applecation爲您提供幾種方法,它允許你通過PHP的Microsoft Word文檔。在這裏查看附加信息http://php.net/manual/en/book.com.php – rgen3

+0

在那個鏈接上他們說如果你在你的錯誤日誌中看到這個: 致命錯誤:未找到'COM'類 你需要這個在php.ini中: PHP_COM_DOTNET extension = php_com_dotnet.dll 我在php.ini中添加了這個,但仍然錯誤,請你告訴我應該在哪裏更改它後更改我的php.ini文件? – user2226181