doumi4676 2009-12-23 11:17
浏览 25
已采纳

使用PHP COM对象打开Word文档

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条回答 默认 最新

  • douhu8851 2009-12-23 11:25
    关注

    /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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行