欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php实现将上传word文件转为html的方法

程序员文章站 2023-11-29 16:14:28
本文实例讲述了php实现将上传word文件转为html的方法。分享给大家供大家参考。具体实现方法如下: 上传页面:

本文实例讲述了php实现将上传word文件转为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>
</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程序设计有所帮助。