faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MySQL : Questions in search of an Answer

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 10 people (30%) answered Yes
Recently 3 of 10 people (30%) answered Yes

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
}
?>