This article describes the method of converting uploading word files into html by PHP. Share it for your reference. The specific implementation method is as follows:
Upload page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>File upload</title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="filename" /> <input type="submit" /> </form> </body> </html>
Receive page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>Receive uploaded files</title> <?php $conn = @new COM(""); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath(""); $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.$($_FILES['filename']["name"],strpos($_FILES['filename']["name"],".")); //Directory name, file name, suffix name echo $uploadfile; echo "<br>"; $temploadfile = $_FILES['filename']['tmp_name']; echo $temploadfile; echo "<br>"; move_uploaded_file($temploadfile , $uploadfile); //Move the file $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 ///f?kz=13975389 function word2html($wfilepath) { $word=new COM("") or die("Unable to open MS Word"); $word->visible = 1 ; $word->Documents->Open($wfilepath)or die("Unable to open this file"); $htmlpath=substr($wfilepath,0,-4); $word->ActiveDocument->SaveAs($htmlpath,8); $word->quit(0); } print( "Word to html is completed!" ); ?> </head> <body> </body> </html>
I hope this article will be helpful to everyone's PHP programming.