本文实例讲述了html\”>php实现将上传word文件转为html的方法。分享给大家供大家参考。具体实现方法如下:
上传页面:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<!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 >
|
接收页面:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<!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程序设计有所帮助。
相关文章
猜你喜欢
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 41
-
2025-05-27 36
-
2025-06-04 83
-
2025-05-27 27
-
2025-05-29 90
热门评论