Seems more and more people are wanting to edit files on-line.
also a common problem in on-line editors is the textarea because editors on-line use the same code,
so it breaks the editor.
first thing is to point it to a file to open,
this part can be done many ways,
but this tutorial does not address those ways or makeing it load different files.
file to open and open it in read mode.
CODE
<?php
$loadcontent = "path/file_name.txt";
$fp = @fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
?>
Now we need a way to to view what we just opened.
So we build a form with textarea to make editable content with a button to save it.
CODE
<form method=post action="<?=$_SERVER['PHP_SELF']?>">
<textarea name="savecontent" cols="70" rows="25"><?=$loadcontent?></textarea>
<br>
<input type="submit" name="save_file" value="Save">
</form>
Function placement? full code belowCODE
<?php
if($save_file) {
$savecontent = stripslashes($savecontent);
$fp = @fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
}
}
?>
so now we have all the parts we need just need them in order so.....
complete code,
CODE
<?php
$loadcontent = "file_name.txt";
if($save_file) {
$savecontent = stripslashes($savecontent);
$fp = @fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
}
}
$fp = @fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
?>
<form method=post action="<?=$_SERVER['PHP_SELF']?>">
<textarea name="savecontent" cols="70" rows="25"><?=$loadcontent?></textarea>
<br>
<input type="submit" name="save_file" value="Save">
</form>
CODE
if you have problems with the server register globals being off,
is 2 ways to fix this.
1) add at the top for all the post feilds in the form,
$save_file = $_POST['save_file'];
$savecontent = $_POST['savecontent'];
for each one.
2) or change them all to ,
if($_POST['save_file']) {
$savecontent = stripslashes($_POST['savecontent']);
A while back i started an online editor
i use on many sites and have added some nice features like,
line #, search, replace, file renameing and some other things.
EasyPHPEditHave Fun
Dave
This post has been edited by SpaceMan: 23 Jan, 2007 - 08:28 PM