fswdnr 发表于 2017-12-30 19:36:14

实现word在线预览 有php的写法 也有插件似

<?php  

//header("Content-type:text/html;");  

//word转html 展示  
$lj=$_GET['file'];//传来的是文件位置 具体看自己的传值 upload/user/20170306/20170306xgtlne.doc
  
$lj=("/",'\\',$lj);//把路径改为\号 例如 upload\user\20170306\20170306xgtlne.doc
  

  
function word2html($wordname,$htmlname)
  
{
  
    $word = new COM("word.application") or die("Unable to instanciate Word");
  
    $word->Visible = 1;
  
    $word->Documents->Open($wordname);
  
    $word->Documents->SaveAs($htmlname,8);
  
    $word->Quit();
  
    $word = null;
  
unset($word);
  

  
}
  
//服务器或本地的word具体位置 例如'D:\phpStudy\WWW\GongshuUnion\.upload\user\20170306\20170306xgtlne.doc'
  
$address='D:\phpStudy\WWW\GongshuUnion\\';
  
word2html($address.$lj,$address.$lj.".html");
  
//跳转时可以在后最加上.html
  
//例如$url=http://localhost/GongshuUnion/upload/user/20170306/20170306xgtlne.doc.html
  
//我这里一共传了两个值 一个是 $_GET['file'] = upload/user/20170306/20170306xgtlne.doc
  
//另一个是$_GET['url']=http://localhost/GongshuUnion/upload/user/20170306/20170306xgtlne.doc.html
  
$url= $_GET['url'];
  
("Location:$url");
  
?>
页: [1]
查看完整版本: 实现word在线预览 有php的写法 也有插件似