Posted By

Jaymoon on 07/08/07


Tagged

edit php file files editor


Versions (?)

Who likes this?

13 people have marked this snippet as a favorite

hudge
Jaymoon
MoFu
tikitakfire
rinx
Hollow
vali29
johnskopa
userpiv
lfcortes
sbcjr
ringo380
tux-world


PHP File Editor


 / Published in: PHP
 

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

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

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

Report this snippet  

You need to login to post a comment.