PHP 读取word的问题: 因为没有打开的文档,所以这一命令无效

cs3810 2014-09-24 09:53:49
代码是这样的:
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
header("Content-Type:text/html; charset=GBK");
$word->Documents->Open(realpath($file_dir . $name));
$content = (string) $word->ActiveDocument->Content;
结果显示:
#Exception: <b>Source:</b> Microsoft Word<br/><b>Description:</b> 因为没有打开的文档,所以这一命令无效。
怎么解决??
...全文
1062 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
cs3810 2014-09-24
  • 打赏
  • 举报
回复
我贴完整的代码吧.. if(!file_exists($file_dir . $name)){ echo '文件不存在'; return; } if(strtolower(substr(strrchr($path, '.'), 1)) == 'doc'){ $word = new COM("word.application") or die ("Could not initialise MS Word object."); header("Content-Type:text/html; charset=GBK"); $word->Documents->Open(realpath($file_dir . $name)); $content = (string) $word->ActiveDocument->Content; }
xuzuning 2014-09-24
  • 打赏
  • 举报
回复
那你就看看是否是 doc 文件
cs3810 2014-09-24
  • 打赏
  • 举报
回复
当然存在呀..应该不是路径的问题
xuzuning 2014-09-24
  • 打赏
  • 举报
回复
echo realpath($file_dir . $name); 检查显示的文件是否存在

20,393

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧