Code Snippets

  

PHP Source Code


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

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





Basic File Editor

This is just a basic file editor taken from a file manager I made. This eliminates most of the problems inherent in the other "online file editor" snippet.

Submitted By: Styx
Actions:
Rating:
Views: 1,339

Language: PHP

Last Modified: March 22, 2007
Instructions: Set $file to the file to be edited.

If the file doesn't exist, it'll be created when you click save.

Snippet


  1. <?php
  2. $file = 'test.php';
  3.  
  4. echo '<div style="border: 1px solid; text-align:center;">';
  5. if (isset($_POST['edit']))
  6. {
  7.   $contents = stripslashes($HTTP_POST_VARS['edit_file']);
  8.  
  9.   $handle = fopen($file, 'w');
  10.   fwrite($handle, $contents);
  11.   fclose($handle);
  12.  
  13.   echo "\n<br />File Updated Successfully!<br />\n";
  14. }
  15.  
  16. $contents = (@file_get_contents($file)) ? htmlspecialchars(file_get_contents($file)) : 'new file';
  17.  
  18. echo '<br /><form method="post">
  19. <textarea name="edit_file" wrap="virtual" cols="90" rows="40">' . $contents . '</textarea>
  20. <br /><br /><input type="submit" name="edit" value="Save"></form>
  21. </div>';
  22. ?>

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

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