首页  >  问答  >  正文

PHP 如何读取word文件转成html代码?

如题!最好支持word里的图片处理,有没有相关的类库?

补充内容:
phpword有没有如题的使用案例,谢谢!

漂亮男人漂亮男人2692 天前1677

全部回复(3)我来回复

  • 代言

    代言2017-06-29 10:10:17

    试试 phpword 吧

    用composer可以引入: packagist上的phpword页面

    回复
    0
  • phpcn_u1582

    phpcn_u15822017-06-29 10:10:17

    Swf 文档生成和展示解决方案(类百度文库) 几年前写的,应该可以帮助你找到思路

    回复
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-29 10:10:17

    上传页面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>文件上传</title>
    </head>
    <body>
      <form action="receivefile.php" method="post" enctype="multipart/form-data">
      <input type="file" name="filename" />
      <input type="submit" />
      </form>
    </body>
    </html>

    接收页面

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>接收上传文件</title>
    <?php
      $conn = @new COM("ADODB.Connection");
      $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("person.mdb");
      $conn->Open($connstr);
      $uploaddir = 'uploads/';
      if(!is_dir($uploaddir)){
        mkdir($uploaddir);
      }
      $filename =$_FILES['filename']['name'];
      $filename =substr($_FILES['filename']["name"],0,strpos($_FILES['filename']["name"],"."));
      echo $filename;
      echo "<br>";
      $uploadfile = $uploaddir.$filename.substr($_FILES['filename']["name"],strpos($_FILES['filename']["name"],"."));
      //目录名.文件名.后缀名
      echo $uploadfile;
      echo "<br>";
      $temploadfile = $_FILES['filename']['tmp_name'];
      echo $temploadfile;
      echo "<br>";
      move_uploaded_file($temploadfile , $uploadfile); //移动文件
      $path = $_SERVER['SCRIPT_FILENAME'];
      $filepath = $_SERVER["PHP_SELF"];
      $path = substr($path,0,strpos($path,$filepath));
      echo $path;
      echo "<br>";
      echo $filepath;
      $htmlpath = $path."/shiyan4/".$uploadfile;
      echo "<br>";
      echo $htmlpath;
      word2html($htmlpath);
      //$query =@mysql_query( "Insert into $username(fname,file)values('$filename','$uploadfile')")or die("error");
    ?>
    <?php
     //http://tieba.baidu.com/f?kz=13975389
     function word2html($wfilepath)
     {
       $word=new COM("Word.Application") or die("无法打开 MS Word");
       $word->visible = 1 ; 
       $word->Documents->Open($wfilepath)or die("无法打开这个文件");
       $htmlpath=substr($wfilepath,0,-4);
       $word->ActiveDocument->SaveAs($htmlpath,8);
       $word->quit(0);
     }
     print( "Word转html完成!" );
    ?>
    </head>
    <body>
    </body>
    </html>

    我也不知道可不可以,你可以试一下。
    另外你说的使用案例,推荐一个PHP程序设计经典案例
    不知道是不是你想要的

    回复
    0
  • 取消回复