php com word to html,PHP Convert word to html with COM

在PHP CLI模式下,一段代码能够成功将Word文档转换为HTML,但在通过Web(Windows/Apache)运行时遇到'com_exception'错误,提示无法创建COM对象。错误发生在尝试创建'word.application'对象时。尝试使用shell_exec包裹代码也未能解决问题。寻求解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

$file='C:/a.doc';

$saveas=__DIR__.'/tmp/a.html';

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

$document=$word->Documents->Open($file);

$document->SaveAs($saveas,8);

$word->Quit();

$word=null;

echo file_get_contents($saveas);

@unlink($saveas);

It works fine in PHP CLI mode(php -f "com_server.php"), but when I run it through web(windows/apache http://localhost/com_server.php), an error occurred:

Fatal error: Uncaught exception 'com_exception' with message 'Failed

to create COM object `word.application': Server execution failed' in

D:\www\wwwroot\com_server.php:16 Stack trace: #0

D:\www\wwwroot\com_server.php(16): com->com('word.applicatio...') #1

{main} thrown in D:\www\wwwroot\com_server.php on line 16

I've also tried to wrap the code in shell_exec, but same error as well.

Any suggestions?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值