2011-08-22 7 views
3

Je veux lire un document Word dans un navigateur en utilisant PHP. J'ai essayé pendant plus de deux heures, mais je ne peux pas le faire fonctionner. Quelqu'un peut-il m'aider à faire cela?Ouvrir un document Word en mode lecture en utilisant php?

+0

Le document Word est-il correct sur votre serveur? –

+0

S'agit-il d'un environnement * nix ou Windows? – Shoan

Répondre

2

Comme votre pas trop détaillé dans votre question sur vos besoins spécifiques ou la configuration du serveur, cela vous aidera à démarrer & répond également à la question.

<?php 
$DocumentPath="C:/xampp/htdocs/test.doc"; 
//Create an instance of the Word application 
$word = new COM("word.application") or die("Unable to instantiate application object"); 
//Creating an instance of the Word Document object 
$wordDocument = new COM("word.document") or die("Unable to instantiate document object"); 
$word->Visible = 0; 
//Open up an empty document 
$wordDocument = $word->Documents->Open($DocumentPath); 

//Create the filename for the HTML version 
$HTMLPath = substr_replace($DocumentPath, 'html', -3, 3); 
//Save the document as HTML 
$wordDocument->SaveAs($HTMLPath, 3); 
// clean up 
$wordDocument = null; 
$word->Quit(); 
$word = null; 
// read the newly-created document 
readfile($HTMLPath); 
//delete the file 
unlink($HTMLPath) 
?> 
Questions connexes