Zubrag.com :: Forum

Programmers Lounge => Tips and Tricks => Topic started by: SlovenianBoy on January 18, 2008, 05:08:10 PM



Title: Simple PHP editor
Post by: SlovenianBoy on January 18, 2008, 05:08:10 PM
Very handy:

Code:
<?php
$file 
'file.txt';

echo 
'<div style="border: 1px solid; text-align:center;">';
if (isset(
$_POST['edit']))
{
  
$contents stripslashes($HTTP_POST_VARS['edit_file']);

  
$handle fopen($file'w');
  
fwrite($handle$contents);
  
fclose($handle);

  echo 
"\n<br />File Updated Successfully!<br />\n";
}

$contents = (@file_get_contents($file)) ? htmlspecialchars(file_get_contents($file)) : 'new file';

echo 
'<br /><form method="post">
<textarea name="edit_file" wrap="virtual" cols="90" rows="40">' 
$contents '</textarea>
<br /><br /><input type="submit" name="edit" value="Save"></form>
</div>'
;
?>