php實(shí)現(xiàn)將上傳word文件轉(zhuǎn)為html的方法
本文實(shí)例講述了php實(shí)現(xiàn)將上傳word文件轉(zhuǎn)為html的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
上傳頁面:
<!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); //移動(dòng)文件
$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("無法打開這個(gè)文件");
$htmlpath=substr($wfilepath,0,-4);
$word->ActiveDocument->SaveAs($htmlpath,8);
$word->quit(0);
}
print( "Word轉(zhuǎn)html完成!" );
?>
</head>
<body>
</body>
</html>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
使用php+Ajax實(shí)現(xiàn)唯一校驗(yàn)實(shí)現(xiàn)代碼[簡(jiǎn)單應(yīng)用]
使用php+Ajax實(shí)現(xiàn)唯一校驗(yàn)實(shí)現(xiàn)代碼[簡(jiǎn)單應(yīng)用],前臺(tái)用ajax后臺(tái)用php,需要的朋友可以參考下。2011-11-11
php簡(jiǎn)單開啟gzip壓縮方法(zlib.output_compression)
網(wǎng)上的教程基本是你抄我來我抄他,不外乎加頭加尾或者自構(gòu)函數(shù)兩種寫法。實(shí)際上每個(gè)php頁面都要去加代碼——當(dāng)然也可以include引用,不過總顯得略微麻煩2013-04-04
詳解PHP 7.4 中數(shù)組延展操作符語法知識(shí)點(diǎn)
在本篇文章里小編給各位整理的是關(guān)于PHP 7.4 中數(shù)組延展操作符語法知識(shí)點(diǎn)內(nèi)容,需要的朋友們參考學(xué)習(xí)下。2019-07-07
PHP中strcmp()和strcasecmp()函數(shù)字符串比較用法分析
這篇文章主要介紹了PHP中strcmp()和strcasecmp()函數(shù)字符串比較用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了strcmp()和strcasecmp()函數(shù)字的功能,使用方法與區(qū)別,需要的朋友可以參考下2016-01-01
過濾掉PHP數(shù)組中的重復(fù)值的實(shí)現(xiàn)代碼
去除一個(gè)數(shù)組中的重復(fù)值,可以使用foreach方法,也可以使用array_unique方法,下面的代碼兩種方法都使用了。2011-07-07
詳解:——如何將圖片儲(chǔ)存在數(shù)據(jù)庫里
詳解:——如何將圖片儲(chǔ)存在數(shù)據(jù)庫里...2006-12-12

