tags:

views:

163

answers:

2

Hi guys,

I've got some code that generates a word document, as follows:

$word->Documents [1]->SaveAs ( $localDir . $filename );

Now, I was kinda hoping that I could now open the file once it's saved by doing the following:

$word->Documents->Open($remoteDir . $filename)

// remotedir = 'word/', so for example the above would be '/word/document1.doc'

But it seems to open it on the host machine, and not the users! Is there anyway to open it on the user's machine and not on the server?

edit: Just for clarity it will be used exclusively on an intranet by a single user that will be on a Windows machine at all times, with Word etc installed... just want to try and make her life a little easier!

Thanks

+2  A: 

/word/document1.doc is the path for a file in the server, not in the client. On Windows, supposing that the file sharing is enabled for the client PC, then you can use a path such as \\IP\word\document1.doc, where IP is the IP of the client PC.
You can get the IP of the PC connecting to the server with $_SERVER['REMOTE_ADDR']; $_SERVER['REMOTE_HOST'] is the result of a DNS reverse lookup, which could return the same value of $_SERVER['REMOTE_ADDR'], in your case.

Probably PHP will not open remote files if it has not been set to do so (there is a directive or that).

If directly accessing the shared file from the COM object doesn't work, then you can copy the file from the client PC to the server in a temporary file, and then give that file to the COM object. In this way, if there are any errors while accessing the networked file, you should be able to get them.

I find strange, anyway, that passing a network file path you get a local file. Are you sure the COM object is not copying of the server the file it finds at the remove file path passed? Did you try with a different file? If that happens with different files too, then we are missing something; I would find strange that for all the network files you try to open, there is already a local file with the same name. Try also renaming the network files.

kiamlaluno
Many thanks - I've got the path working okay now, so when I echo it out and paste it into the address bar (with http:// etc too) it works, but it's still doing the thing where it opens it on the server instead of the client :(
Nick
Check the name and the IP assigned to both the PCs, the value of `$_SERVER['REMOTE_ADDR']`, and if file sharing is enabled on the client PC. The path I reported is the path used to access a network file; if you are getting the local file, then it could be that PHP is not enabled to access remote files as if they would be local, or that PHP COM doesn't access the remote files.
kiamlaluno
Many thanks - just tried that, same thing unfortunately, it opens them but it opens them on the server! Not on the client :(
Nick
A: 

I think you are fundamentally mistaken about what runs where. PHP is a purely server side language. You can not use it to open a file on the client's PC so that the user has an opened instance of Word in front of them.

You can maybe achieve that through client side Scripting, namely in VBScript or some other Microsoft scripting flavour. Be prepared for massive obstacles and incompatibilities, though, because such things are blocked for security reasons by default in all browsers, and sometimes those blocks cannot be circumvented even with special settings ("Trusted sites") in the client browser.

You may be able to display the document in the user's browser as an embedded HTML object.

The most simple thing really may be generating the file, and offering it to the user as a download. The user can then save it, and open it. Job done.

Pekka