Page 1 of 1

Hum,,, how does com with php work....

Posted: Fri Jan 12, 2007 1:01 pm
by PHP_ColdFusion
i am trying to open an instance of notepad through php.

below is the code.

Code: Select all

<?php

// starting word
$word = new COM("word.application");
echo "Loaded Word, version {$word->Version}\n";

//bring it to front
$word->Visible = 1;

//open an empty document
$word->Documents->Add();

//do some weird stuff
$word->Selection->TypeText("This is a test");
$word->Documents[1]->SaveAs("Useless test.doc");

//closing word
$word->Quit();

//free the object
$word = null;

?>
but when i run that php file i get this

Code: Select all

Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `word.application': Invalid syntax ' in F:\Database Program\WEBPROGRAM\com.php:4 Stack trace: #0 F:\Database Program\WEBPROGRAM\com.php(4): com->com('word.applicatio...') #1 {main} thrown in F:\Database Program\WEBPROGRAM\com.php on line 4
what am i doing wrong

Posted: Fri Jan 12, 2007 1:13 pm
by PHP_ColdFusion
heh, ok all references to word.application are acctually notepad.application in the script

i didn't notice i did that

but i still get the error.

Posted: Fri Jan 12, 2007 2:12 pm
by kingconnections
is Notepad installed on your server? Because if you are trying to open this on the client it will not work. PHP is a server side language. You would need to use javascript or something to open it on the client.

Posted: Fri Jan 12, 2007 2:50 pm
by PHP_ColdFusion
i know php is server side but i'm not sure if notepad is installed should be tho its pretty basic windows component lol

Posted: Fri Jan 12, 2007 2:52 pm
by PHP_ColdFusion
notepad is installed

Posted: Fri Jan 12, 2007 3:22 pm
by kingconnections
So are you trying to open up notepad, on the server, or the client's browser?

Posted: Fri Jan 12, 2007 3:31 pm
by PHP_ColdFusion
on the server

Posted: Fri Jan 12, 2007 4:02 pm
by kingconnections
hmmm I have done similar type things using com.... let me find one of my old scripts. I didn't use notepad but may be able to help.

Posted: Fri Jan 12, 2007 4:56 pm
by volka
PHP_ColdFusion wrote:heh, ok all references to word.application are acctually notepad.application in the script
But there is no application id notepad.application. Notepad simply doesn't offer such an interface.

Posted: Fri Jan 12, 2007 5:11 pm
by Kieran Huggins
Do you mean wordpad? notepad doesn't open or save .doc files

Posted: Mon Jan 15, 2007 8:40 am
by PHP_ColdFusion
HUM....well i guess i could use wordpad for it
let me try