PHP
  Home arrow PHP arrow Page 4 - PHP and COM
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP and COM
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2002-04-23

    Table of Contents:
  • PHP and COM
  • Striving To Excel
  • The Number Game
  • Export Potential
  • Keeping It Simple
  • Access-ing The Web
  • All For One, And One For All
  • New Coins For Old
  • Link Zone

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PHP and COM - Export Potential


    (Page 4 of 9 )

    Let's look at something a little more interesting. I've always considered Microsoft Word to be one of the best editing tools to ever come out of Redmond - and one of its nicest features, especially for Web newbies, is the ability to quickly convert a formatted Word document into an HTML file suitable for use on a Web site.

    That's where my next example comes in. It uses Word's built-in export-to-HTML feature in combination with a PHP script to give new meaning to the term "tighter Web integration". Watch, and be awed!

    The first step here is to write a script that displays a list of all the Word documents available on the system. There's nothing fancy here - this is just very basic usage of PHP's file and directory functions.



    <?php // where are the files stored? $PathToDocumentFolder = "C:\\My Stuff\\Documents"; ?> <html> <head> <basefont face="Arial"> <title>My Documents</title> </head> <body> <h2>My Documents</h2> <table border="2" cellpadding="5" cellspacing="1" width="90%"> <tr> <th width="55%" align="left">Name</th> <th width="20%" align="center">&nbsp;</th> <th width="20%" align="center">&nbsp;</th> </tr> <?php // get a handle to the document folder $dHandle = dir($PathToDocumentFolder); // iterate through the file list while($dContent=$dHandle->read()) { // only list the .doc files if(substr($dContent,-4)== ".doc") { ?> <tr> <td width="55%" align="left"><?php echo $dContent; ?></td> <td width="20%" align="center"><a href="<?php echo $PathToDocumentFolder."\\".$dContent; ?>">View as Word</a></td> <td width="20%" align="center"><a href="<?php echo "htmlviewer.php?DocumentPath=".$PathToDocumentFolder."\\".$dContent; ?>">View as HTML</a></td> </tr> <?php } } // close the handle to the directory $dHandle->close(); ?> </table> </body> </html>
    Here's what it looks like:



    The first step here is to initialize a variable containing the location of the directory containing the Word documents.

    <?php // where are the files stored? $PathToDocumentFolder = "C:\\My Stuff\\Documents\\"; ?>
    Next, a table is generated and a PHP "while" loop is used to populate it with a file list of Word documents in that directory.

    <?php // get a handler to the document folder $dHandle = dir($PathToDocumentFolder); // iterate through the file list while($dContent=$dHandle->read()) { // only list the .doc files if(substr($dContent,-4)== ".doc") { ?> <tr> <td width="55%" align="left"><?php echo $dContent; ?></td> <td width="20%" align="center"><a href="<?php echo $PathToDocumentFolder."\\".$dContent; ?>">View as Word</a></td> <td width="20%" align="center"><a href="<?php echo "htmlviewer.php?DocumentPath=".$PathToDocumentFolder."\\".$dContent; ?>">View as HTML</a></td> </tr> <?php } } ?>
    Within this code block, the first step is to create a directory handle for the named location. This "pseudo-object" gives me access to several methods that will allows us to read the contents of the directory, move back to the root folder, close this handle and so on.

    Once I have the object created, I've used a "while" loop to read the contents of the directory, and an "if" test to filter out all the non-Word files, on the basis of the ".doc" file extension. Each of the files in the final list is then displayed as a separate row in the table, complete with links to view it, either as a Word document within the browser itself, or as an HTML document via the "htmlviewer.php" script.

    This "htmlviewer.php" script is where all the meat really is. Let's take a look at that next.

    More PHP Articles
    More By Harish Kamath, (c) Melonfire


     

       

    PHP ARTICLES

    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway