Click to See Complete Forum and Search --> : diplaying a word doc


Alicia
12-10-2003, 08:51 PM
Hi guys,

Can i actually display a word document by using php ? As far as i know, i can display the contents of text file by using php. But will it works on word document ??

If yes, is that mean it will able to display the hyperlinks and images that are inserted in the word document as well ? In other words, will it display exactly like what i have done on the word document ?

p.s: by the way, what is MIME extension shown in the php info for ?

Please advise.

Kyleva2204
12-10-2003, 08:59 PM
Um yea its possible. I saw a script on the internet that did it. Lemme grab the URL for u. Also I dunno about the mime thing. Originally posted by Alicia
Hi guys,

Can i actually display a word document by using php ? As far as i know, i can display the contents of text file by using php. But will it works on word document ??

If yes, is that mean it will able to display the hyperlinks and images that are inserted in the word document as well ? In other words, will it display exactly like what i have done on the word document ?

p.s: by the way, what is MIME extension shown in the php info for ?

Please advise.

Kyleva2204
12-10-2003, 09:06 PM
Created and copyrighted by Mark Warburton - spam2@instruform.com
you need wvWare - http://wvware.sourceforge.net to use this. It might or might not be installed on your server.

<?
/* Usage - call base URL and add wordconv.php?name=xxx where xxx =
filename of .doc file to be converted (without .doc extension)
For example:
http://mydomain/mydirectory/wordconv/wordconv.php?name=try
to convert try.doc in mydirectory
* Create a subdirectory called wordconv and make it readable and
writable by the web server (aka php) process.
* Put this script into the wordconv subdirectory. The parent
directory should contain the .doc file.
* To prevent a security problem make this script read only to the
web server process.

This script will create all .html, .png, etc. files in the wordconv
subdirectory. The .html files will not be deleted after serving.
The created html files are reconverted when the modification time
on the .doc file is newer than the .html file. If the .html file
is already present, it is served up directly (i.e. cached) without
reconversion.

Requires:
PHP - http://www.php.net
wvWare - http://wvware.sourceforge.net

Note:
Change the path of wvWare in the $wvware variable below to match
the path of your wvWare executable.

Created and copyrighted by Mark Warburton - spam2@instruform.com
11 Jan 2002
Licensed under the GPL.
Revision History:
v1.01 15 Jan 2002 Moved the script to the wordconv subdirectory
to ensure that URL for created graphics is correct.
v1.02 30 Jan 2002 Add a sanity check to ensure that the wvWare
executable is present and executable.
*/

/* Where is wvware installed? Command line options? */
$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);
?>

pyro
12-10-2003, 09:07 PM
Do you mean the default_mimetype?