PHP File Editor


/ Published in: PHP
Save to your folder(s)

The original code was meant to be used with register_globals=on.
If you cannot or don't want to turn that on, then I have modified the code to work with register_globals=off.


Copy this code and paste it in your HTML
  1. <?php
  2. $loadcontent = "test-edit.php";
  3.  
  4.  
  5. if($_POST['save_file']) {
  6. $savecontent = stripslashes($_POST['savecontent']);
  7. $fp = @fopen($loadcontent, "w");
  8. if ($fp) {
  9. fwrite($fp, $savecontent);
  10. fclose($fp);
  11. print "<html><head><META http-equiv=\"refresh\" content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>";
  12.  
  13. }
  14. }
  15. $fp = @fopen($loadcontent, "r");
  16. $loadcontent = fread($fp, filesize($loadcontent));
  17. $lines = explode("\n", $loadcontent);
  18. $count = count($lines);
  19. $loadcontent = htmlspecialchars($loadcontent);
  20. fclose($fp);
  21. for ($a = 1; $a < $count+1; $a++) {
  22. $line .= "$a\n";
  23. }
  24. ?>
  25.  
  26. <p><font face="tahoma">Simply edit the page and hit save!</font></p>
  27.  
  28. <form method=post action="<?=$_SERVER[PHP_SELF]?>">
  29. <input type="submit" name="save_file" value="Save"><br /><br />
  30. <table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
  31. <tr>
  32. <td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; overflow: auto; border: 0px groove; font-size: 12px; font-face:verdana;" name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre></td>
  33. <td width="97%" align="left" valign="top"><textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; font-size: 12px; font-face:verdana;" name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF"><?=$loadcontent?>

URL: http://www.dreamincode.net/code/snippet99.htm

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.