properies profile when writing word file
Posted
by avani-nature
on Stack Overflow
See other posts from Stack Overflow
or by avani-nature
Published on 2010-05-24T09:23:00Z
Indexed on
2010/05/24
9:41 UTC
Read the original article
Hit count: 300
php
Hai frnds i am new to php i am having following problems in my coding... 1.Actually i am opening word document with com object and storing it in textarea. 2.when content gets opened in textarea i am editing that content and saving the document 3.actually when i edited that file and done save after that if i open word document then file properties->custom the old content getting removed i wannt to retain that even if i edited the word document..please do the needful i am using below code
<?php
$filename = 'C:/xampp/htdocs/mts/sites/default/files/a.doc';
//echo $filename;
if(isset($_REQUEST['Save'])){
$somecontent = stripslashes($_POST['somecontent']);
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened fi<form action="" method="get"></form>le.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename) <a href=".$_SERVER['PHP_SELF']."> - Continue - ";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
}
else{
// get contents of a file into a string
$handle = fopen($filename, "r");
$somecontent = fread($handle, filesize($filename));
$word = new COM("word.application") or die ("Could not initialise MS Word object.");
$word->Documents->Open(realpath("$filename"));
// Extract content.
$somecontent = (string) $word->ActiveDocument->Content;
//echo $somecontent;
$word->ActiveDocument->Close(false);
$word->Quit();
$word = null;
unset($word);
fclose($handle);
}
?>
<h6>Edit file --------><? $filenam=explode("/",$filename);$filename=$filename[7]; echo $filename ;?></h6>
<form name="form1" method="post" action="">
<p>
<textarea name="somecontent" cols="100" rows="20"><? echo $somecontent ;?></textarea>
</p>
<div style='padding-left:250px;'><input type="submit" name="Save" value="Save"></div>
</p>
</form>
<?
}
?>
© Stack Overflow or respective owner