Code Snippets

  

PHP Source Code


Welcome to Dream.In.Code
Become a PHP Expert!

Join 148,673 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,597 people online right now. Registration is fast and FREE... Join Now!



Submitted By: SpaceMan
Actions:
Rating:
Views: 15,041

Language: PHP

Last Modified: March 13, 2005
Instructions: chmod the file to edit 0666.
will edit files with textarea.

Snippet


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

Copy & Paste


Comments


SpaceMan 2008-02-12 07:04:32

CODE
a55af5fc51c7b97d34fd531a6822}r globals would need to be on for this to work. easy change if not. change. [CODE] if($save_file) { $savecontent = stripslashes($savecontent); [/CODE] to... [CODE] if($_POST['save_file']) { $savecontent = stripslashes($_POST['savecontent']); [
55af5fc51c7b97d34fd531a6822}r globals would need to be on for this to work. easy change if not. change. [CODE] if($save_file) { $savecontent = stripslashes($savecontent); [/CODE] to... [CODE] if($_POST['save_file']) { $savecontent = stripslashes($_POST['savecontent']); [/CODE]

lazar89 2008-11-17 09:32:52

not vorking


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month