首页 > 解决方案 > php 中缺少类 php_com_dotnet

问题描述

所以我在我的代码中使用了调用 php_com_dotnet:

$word = new COM("word.application");

// Hide MS Word application window
$word->Visible = 0;

//Create new document
$word->Documents->Add();

// Define page margins
$word->Selection->PageSetup->LeftMargin = '2';
$word->Selection->PageSetup->RightMargin = '2';

// Define font settings
$word->Selection->Font->Name = 'Arial';
$word->Selection->Font->Size = 10;

// Add text
$word->Selection->TypeText("TEXT!");

// Save document
$filename = tempnam(sys_get_temp_dir(), "word");
$word->Documents[1]->SaveAs($filename);

// Close and quit
$word->quit();
unset($word);

header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");

// Send file to browser
readfile($filename);
unlink($filename);

我得到了他的错误:

致命错误:未捕获的错误:在 /var/www/clients/client1/web1/web/nordin/save.php:6 中找不到类“COM”堆栈跟踪:在 /var/www/clients/ 中抛出 #0 {main}第 6 行的 client1/web1/web/nordin/save.php

所以我环顾四周,将其添加到我的 php.ini 文件中:

 [COM_DOT_NET]
 ;extension=php_com_dotnet.dll

 enable_dl = On
 ; extension_dir = "ext"

它仍然不起作用,我做错了什么?请帮忙!

编辑

我的文件在 sftp 服务器上,出现如下错误:

 ini_set('display_errors', 1);
 ini_set('display_startup_errors', 1);
 error_reporting(E_ALL);

标签: phpcom

解决方案


扩展名前的分号是注释,表示未启用扩展名。要启用它,您必须删除该分号:

;extension=php_com_dotnet.dll

变成

extension=php_com_dotnet.dll

进行此更改后,您可能需要重新启动 IIS。


推荐阅读