PHP将word转化为网页

wulongda 2015-12-11 11:30:12
我在网上找到一段代码运行,结果出现为 Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> 操作已被取消。' in C:\Program Files\WWW\wordToPhp.php:11 Stack trace: #0 C:\Program Files\WWW\wordToPhp.php(11): com->Open('DRIVER={Microso...') #1 {main} thrown in C:\Program Files\WWW\wordToPhp.php on line 11

代码如下
<?php
$conn = new COM("ADODB.Connection") or die("Unable to instanciate Word");
$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完成!" );
?>
...全文
125 点赞 收藏 回复
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
PHP
创建于2008-08-27

1.9w+

社区成员

“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
申请成为版主
帖子事件
创建了帖子
2015-12-11 11:30
社区公告
暂无公告