COM() hassle

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jonemo
Forum Commoner
Posts: 28
Joined: Wed Feb 09, 2005 1:32 pm
Location: london, uk

COM() hassle

Post by jonemo »

I am trying to use COM to get the text content out of msword files (and put them into a database to build a full text search). The machine is a Apache running on Win2000, Microsoft Office 2000 is installed. The following problem also occurs using Office XP. Now the prob(s):

Code: Select all

$word = new COM("Word.Application");
Apache crashes.

Code: Select all

$word = com_load("Word.Application");
$word->visible = $visible ;
$word->Documents->Open($filename)
Works fine. Word starts and loads the file. if i do not use com further the script works fine and nothing extrordniary happens. BUT

Code: Select all

$word->ActiveDocument->SaveAs($filename_path, 2);
and

Code: Select all

$word->Quit();
make the server crash.

It seems like i made all required settings as the file loads. I cant understand at all, why closing the app lets the whole server go. What I already tried to fix it: Reinstalled Office. Checked, that the files will open properly if i open them manually. Wrote into thoundands of other forums where folks couldnt help me.

Would be great, if you guys had some suggestions as i carry that problem aroudn for nearly two months now and am just stuck with it.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I know this isn't the idea you're trying to accomplish, but it might lead you in the right direction:

http://www.phpbuilder.com/columns/yunus20031124.php3

Burr
jonemo
Forum Commoner
Posts: 28
Joined: Wed Feb 09, 2005 1:32 pm
Location: london, uk

Post by jonemo »

Cheers Burr, but that article isnt new for me. That script uses the same functions as i do a more or less similar way. And it crashes at the same point. The text there doesnt contain any new info.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

well then this probably won't help as we wrote it almost directly from that article...but give it a look and see anyway...

Code: Select all

<?php
require_once("phphttp.php");

function html2word($urlFrom, $locTo,  $isURL = "yes", $leaveopen = FALSE)
&#123;
	if($isURL != "yes")&#123;
  $doctext = $urlFrom;
    &#125;else&#123;
  $doctext = phphttp($urlFrom);
    &#125;
  $fname = "";
  while (file_exists($fname = get_cfg_var('upload_tmp_dir') . "\\tmpHtml2Word" . mt_rand(1,10000) . ".html"));
  $htmfile = fopen($fname, "wb");
  if (fwrite($htmfile, $doctext, strlen($doctext)) === FALSE)
    return "Couldn't write html file";
  fclose($htmfile);
  $objWord =  new COM("Word.Application");
  if ($objWord === FALSE)
    return "Couldn't connect to word";
  if (file_exists($locTo . ".doc"))
    unlink($locTo . ".doc");
  $objWord->Visible = FALSE;
  $objWord->DisplayAlerts = FALSE;
  $objDoc = $objWord->Documents;
  if ($objDoc)
  &#123;
    $newDoc = $objDoc->open($fname);
    if ($newDoc)
    &#123;
      $newDoc->SaveAs($locTo . ".doc", 1);
      $newDoc->Close();
    &#125;
  &#125;
  if (!$leaveopen)
  &#123;
    $objWord->Quit();
  &#125;
  $objWord->Release();
  $objWord = null;
  unlink($fname);
  return TRUE;
&#125;
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the (originally posted) code works for me, just fine. Check the server logs?
Post Reply