I want a webpage that can open another webpage, edit the contents and then save the changes.
I can do this using the functions fread and fwrite, however the pages I'm trying to edit contain both html and php.
I use fread then put the contents into a <textarea>, the problem is that the files I'm editing contain the tag </textarea> so at that point the contents of the file are no longer displayed in the text area - some lines go missing and the rest is displayed outside the textarea.
I've tried various ideas including stripslashes and htmlentities to no avail.
<?php
// set file to read
$filename = "testfile.php";
$newdata = $_GET['newdata'];
if ($newdata != '') {
// open file
$fw = fopen($filename, 'w') or die('Could not open file!');
// write to file
// added stripslashes to $newdata
$fb = fwrite($fw,stripslashes($newdata)) or die('Could not write
to file');
// close file
fclose($fw);
}
// open file
$fh = fopen($filename, "r") or die("Could not open file!");
// read file contents
$data = fread($fh, filesize($filename)) or die("Could not read file!");
// close file
fclose($fh);
// print file contents
echo "<h3>Contents of File</h3>
<form action='$_SERVER[php_self]' method= 'get' >
<textarea name='newdata' cols='100%' rows='500'> $data </textarea>
<input type='submit' value='Change'>
</form>";
?>
And an excerpt from a testfile.php that causes this problem:
if($_GET['edit']=='on'){
echo "
<center>
<br/><br/>
<form METHOD=post action=index.php?edit=done&page=".$page.">
<textarea name=content cols=90 rows=40>".mysql_result($result,0,'content')."</textarea>
<br/>
<input type=submit value=Save>
</form>
</center>";
}
Thanks for reading.