Convert .doc to html in php [closed]
Asked Answered
R

5

10

Has anyone found a good class, or other file that will convert a .doc file into html or something that I can read and turn into html?

I have been looking around for a couple hours now and have only found ones that require msword on the server in order to convert the file. I am pretty sure that is not an option but I have not actually talked to my hosting provider about it.

The goal is for a user to be able to upload the file to my server and the server handle the conversion and then display it as html, much like googles view as html feature.

Retraction answered 31/10, 2008 at 15:2 Comment(0)
F
6

intall and use abiword, like this:

AbiWord --to=html archivo.doc

you can call this command from php.

Fugere answered 3/6, 2010 at 17:7 Comment(3)
can i use it along side with my webserver for fast conversion ?Foxhole
@Papa_Jay yes, you can (I used it several years ago in a joomla plugin...)Fugere
It is having issues with some of doc files. Not a 100% proof solution.Grain
M
3

A project called phpLiveDocx does what you want. It is a SOAP based service, but can be used free of charge. For a basic introduction, please see: http://www.phplivedocx.org/articles/brief-introduction-to-phplivedocx/

Minnesinger answered 17/2, 2009 at 11:33 Comment(0)
E
0

Install open office on your system and run this on the command line:

/usr/bin/soffice -headless "macro:///Standard.Convert.SaveAsHtml(test.doc)"

Everywhere answered 27/5, 2010 at 11:1 Comment(1)
thanks Anthony, but i could not find any documentation about that. could you provide a reference?Tabaret
S
0

You can do it through openoffice with unoconv http://dag.wieers.com/home-made/unoconv/ Really great tool.

Stodgy answered 26/11, 2010 at 0:15 Comment(0)
R
0

This PHP uploads your *.DOC file to a upload folder and opens it up in HTML.

<?php
function content($file){
$data_array = explode(chr(0x0D),fread(fopen($file, "r"), filesize($file)));
$data_text = "";
foreach($data_array as $data_line){
if (strpos($data_line, chr(0x00) !== false)||(strlen($data_line)==0))
{} else {if(chr(0)) {$data_text .= "<br>";
                      $data_text .= preg_replace("/[^a-zA-Z0-9\s\,\.\-\n\r\t@\/\_\(\)]/","",$data_line); 
       } 
   }        
}
return $data_text;}
$destination = str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']);
$destination.= "upload/";
$maxsize = 5120000;
if (isset($_GET['upload'])) {
      if($_FILES['userfile']['name'] && $_FILES['userfile']['size'] < $maxsize) {
      if(move_uploaded_file($_FILES['userfile']['tmp_name'], "$destination/".$_FILES['userfile']['name'])){
      $file = $destination."/".$_FILES['userfile']['name'];
      $data = content($file);
      echo $data;
        }   
         }
}else{
      echo "<form  enctype='multipart/form-data' method='post' action='index.php?upload'>
            <input name='userfile' type='file'>
            <input value='Upload' name='submit' type='submit'>
            </form>";
      }
?>
Retrench answered 4/7, 2012 at 19:33 Comment(2)
sorry but your function produces something not readable: "<br>Gino/1Af3TI SWY<br>5Ng2yyu1UIJCC o5uGGg1vQesK,Vq5toYon8oOcwt6_j-yct/_z...."Impoverish
and it will given just plan text can we get with formatting?Kozloski

© 2022 - 2024 — McMap. All rights reserved.