convert doc to text

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
roopa
Forum Newbie
Posts: 2
Joined: Mon May 17, 2010 1:18 am

convert doc to text

Post by roopa »

hi i i have written the code doc to text but error is display

<?php
$filename="cv.doc";
$TXTfilename = $filename . ".txt";
$word = new COM("word.application") or die("Unable to instantiate Word object");
$word->Documents->Open($filename);
$word->Documents[1]->SaveAs($TXTfilename ,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);
$content = file_get_contents($TXTfilename);
unlink($TXTfilename);
?>



Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Word<br/><b>Description:</b> This file could not be found. (C:\WINDOWS\system32\cv.doc)' in C:\wamp\www\readword _doc\sample_new\sample1.php:5 Stack trace: #0 C:\wamp\www\readword _doc\sample_new\sample1.php(5): variant->Open('cv.doc') #1 {main} thrown in C:\wamp\www\readword _doc\sample_new\sample1.php on line 5
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: convert doc to text

Post by cpetercarter »

I guess that line 5 of your code needs the path to the file you want to open, not just the file name. Or perhaps the COM class has a method which sets the directory where documents are located, which you need to call before trying to open a document.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: convert doc to text

Post by mikosiko »

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft Word<br/><b>Description:</b> This file could not be found. (C:\WINDOWS\system32\cv.doc)'

message seems very clear to me.... as cpetercarter said... define the path where the file is located
Post Reply