Entry
How do I make a simple text file editor?
Apr 30th, 2005 09:50
Philipp Gérard, John Harkins, Onno Benschop,
First let the user select a file he wants to edit, second open it using
file() and implode(). It's really easy, try a little but keep an eye on
securety related questions, i.e. restrict file-access to a specific
folder etc.
Example using a lot of pseudo-code:
<?php
if($_REQUEST["edit"] == 1){
write_changes_to_file();
die("File edited successfully.");
}
if(!$_REQUEST["edit"]){
do_show_files_users_can_edit();
} else {
?>
<form action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="edit" value="1" />
<textarea name="file" rows="15"><?=htmlentities($data);?></textarea>
<input type="submit" />
</form>
<?php
}
?>