views:

42

answers:

0

Hi, Here is my code:

            $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?

Thanks

Dong