当前位置:Gxlcms > PHP教程 > php实现将上传word文件转为html的方法_php技巧

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

时间:2021-07-01 10:21:17 帮助过:14人阅读

本文实例讲述了php实现将上传word文件转为html的方法。分享给大家供大家参考。具体实现方法如下:

上传页面:





文件上传


  



接收页面:





接收上传文件
<?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 "
"; $uploadfile = $uploaddir.$filename.substr($_FILES['filename']["name"],strpos($_FILES['filename']["name"],".")); //目录名.文件名.后缀名 echo $uploadfile; echo "
"; $temploadfile = $_FILES['filename']['tmp_name']; echo $temploadfile; echo "
"; move_uploaded_file($temploadfile , $uploadfile); //移动文件 $path = $_SERVER['SCRIPT_FILENAME']; $filepath = $_SERVER["PHP_SELF"]; $path = substr($path,0,strpos($path,$filepath)); echo $path; echo "
"; echo $filepath; $htmlpath = $path."/shiyan4/".$uploadfile; echo "
"; 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完成!" ); ?>

希望本文所述对大家的php程序设计有所帮助。

人气教程排行