Home > Backend Development > PHP Tutorial > PHP method to convert uploaded word files into HTML_PHP tutorial

PHP method to convert uploaded word files into HTML_PHP tutorial

WBOY
Release: 2016-07-13 09:52:00
Original
768 people have browsed it

How to convert uploaded word files to html in php

This article describes the example of how to convert uploaded word files to html in php. Share it with everyone for your reference. The specific implementation method is as follows:

Upload page:

 ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

文件上传

1 2 3 4 5 6 7 8 9 10 11 12 13 14
<🎜>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> File upload

Receiving page:

 ?

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

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

接收上传文件

$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");

?>

//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完成!" );

?>

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
<🎜>"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Receive uploaded files <🎜>$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"],".")); //Directory name.File name.Suffix name echo $uploadfile; echo "
"; $temploadfile = $_FILES['filename']['tmp_name']; echo $temploadfile; echo "
"; move_uploaded_file($temploadfile, $uploadfile); //Move file $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"); ?> <🎜>//http://tieba.baidu.com/f?kz=13975389<🎜> <🎜>function word2html($wfilepath)<🎜> <🎜>{<🎜> <🎜>$word=new COM("Word.Application") or die("Cannot open MS Word");<🎜> <🎜>$word->visible = 1 ; $word->Documents->Open($wfilepath)or die("Cannot open this file"); $htmlpath=substr($wfilepath,0,-4); $word->ActiveDocument->SaveAs($htmlpath,8); $word->quit(0); } print( "Word to HTML converted!" ); ?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1011122.htmlTechArticleHow to convert uploaded word files into html using php. This article explains how to convert uploaded word files into html using php. method. Share it with everyone for your reference. The specific implementation method is as follows: Above...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template