Code Snippets

  

PHP Source Code


Welcome to Dream.In.Code
Click Here
Getting PHP Help is Easy!

Join 118,478 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 939 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!


Submitted By: SpaceMan
Actions:
Rating:
Views: 13,522

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]


Add comment


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





Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month