How to View a Word Document From PHP (4 Steps)
By Jim Campbell
Word documents are rich-text documents that allow you to create newsletters, contracts and other customer communication. You can display these Word documents in the user's browser using the PHP programming language. The PHP programming language provides developers with a free resource to create dynamic webpages. You can create dynamic content by displaying a Word document for the web reader.
Create your Word application and file name variable. These variables are required to point PHP to the file and use the internal Word functions. The following code creates the variables:
$app= new COM("Word.Application"); $file = "/worddoc.doc";
Open the Word document and set its attribute to visible. The following code opens the Word document:
$app->visible = true; $app->Documents->Open($file);
Print out the Word document to the web browser. The following code prints the Word document to the browser, so your readers can view the file:
Close the document and quit the application. The Word document still displays in the user's browser, but the memory resources are freed on the server. The following code closes your document:
Jim Campbell has been a computer engineer for over five years. He excels in hardware repair, computer programming and troubleshooting, and software design. He is currently attending Florida Atlantic University, pursuing a master's degree in computer and electrical engineering and fine-tuning his technical writing abilities.