<?
    $wvware = "/usr/bin/wvWare";
    $wvware_options = "-d";
       
    function updateword($wordfilename, $htmlfilename) {
        global $wvware, $wvware_options;
        $htmldir = dirname ($htmlfilename);
        /* ensure that we get any images into the html directory */
        exec("$wvware $wvware_options $htmldir $wordfilename > $htmlfilename");
        readfile($htmlfilename);
    }
    
    /* What absolute directory are we in on the file system? */
    $basedir = dirname (  getenv ("SCRIPT_FILENAME") ); 
    
    /* Work relative to this directory */
    $wordfilename = $basedir . "/../" . escapeshellcmd($name) . ".doc";
    
    $htmldir = $basedir . "/";
    $htmlfilename = $htmldir . escapeshellcmd($name) . ".html";
    
    /* Sanity checks */
    if (! file_exists($wordfilename)) 
        die("Unable to open file $name ($wordfilename). Set URL variable " .
            "?name=xxx to the base filename of the word file (e.g. try " .
            "for try.doc).  Do not include path!  This script should be in " .
            "the wordconv subdirectory to the .doc file.");
    if (! is_dir($htmldir))
        die("Directory $htmldir does not exist.  It must be " .
            "created and readable and writable by your web server.");
    if ((! is_writeable($htmldir)) || (! is_readable($htmldir)))
        die("Directory $htmldir must be readable and writable by your " .
            "web server.");
    if (file_exists($htmlfilename) && (! is_writeable($htmlfilename)))
        die("The html file ($htmlfilename) exists already but is not " .
            "writable by the web server.");
    if (! file_exists($wvware))
        die("The wvWare executable file $wvware cannot be found.  Please " .
            "ensure that the \$wvware variable in the script is pointed " .
            "to your wvware executable.");
    if (! is_executable($wvware))
        die("The wvWare executable file $wvware is not " .
            "executable by the web server process.  Please change the file " .
            "permissions to make it executable.");

    /* Do the work */
    if (file_exists($htmlfilename)) {
        /* Do we need to update the html file? */
        if (filectime($wordfilename) > filectime($htmlfilename))
            updateword($wordfilename, $htmlfilename);
        else readfile ($htmlfilename);
    }
    else  updateword($wordfilename, $htmlfilename);
?>
Published in: PHP
Download

Related snippets