Version: 1

Type: Sample Code (HOWTO)

Category: File Management

License: GNU General Public License

Description: It edits pages simply through fopen and opendir



<?php
/*
Please follow these instructions:'
Put this code in a file and make this file "webedit.inc"
--------------------------------------------------
class webedit {
var $con;
var $mdir;
function open($dir) {
$this->mdir=dir($dir);
}
function read($dir) {
while($x = $dir->read()) {
echo "<A HREF='$PHP_SELF?web=edit&file=$x'>$x</A> <A HREF='$PHP_SELF?web=delete&file=$x'>Delete</a>";
}
}
function edit($file) {
$fp=fopen($file, "w");
$this->con=fread($fp, filesize($file));
fclose($fp);
echo "<TEXTAREA ROWS='20' COLS='30'>\n";
echo $this->con;
echo "</TEXTAREA>";
}
function delete($file) { unlink($file); }
}
$editor=new webedit;
----------------------------------------------------
That's it!
*/
include "webedit.inc";
if($web == "view") {
$editor->open(".");
$editor->read($editor->mdir);
} elseif($web == "edit") {
echo "<FORM ACTION='$PHP_SELF?web=save' METHOD='post'>\n";
echo "Editing File: $file<BR>\n";
$editor->edit($file);
echo "<input type=submit value=Save>";
} elseif($web == "delete") {
delete($file);
} else {
// Anyone make a html frame here?
}
?>