Skip to content

Instantly share code, notes, and snippets.



Last active Jan 3, 2016
What would you like to do?
A knowledge management system we created in under 5 minutes
$title = "Knowledge Base 0.1";
$datadir = './data/';
if (!is_dir($datadir) || !is_writable($datadir)) die('The DATADIR directory must be writable');
<title><?= $title ?></title>
<link rel="stylesheet" href="//">
<link rel="stylesheet" href="//">
<td width="25%" style="background:#ddf">
* Returns a list of all files in the photostore
* @return an array of files, in the form 'path'=>basename(path)
function ListFiles($path = '', $recur=TRUE)
global $datadir;
$retval = array();
$prefix = $datadir;
if ($dir = @opendir($prefix . '/' . $path))
$children = array();
while (false !== ($file = readdir($dir)))
if ($file[0]=='.') continue;
$photopath = $path.$file;
if ($recur && is_dir($prefix . '/' . $photopath))
$retval[$photopath] = 'dir';
$retval += ListFiles($photopath . '/');
else if (is_file($prefix . '/' . $photopath))
$retval[$photopath] = 'text';
return $retval;
return $retval;
echo "<h2><a href=\"?\">$title</a></h2>";
echo '<ul style="list-style:none; margin:0; padding:0">';
foreach (ListFiles() as $name=>$type) {
$level = count(split('/',$name));
$weight = $name == $_GET['dir'].$_GET['text'] ? 'bold' : 'normal';
echo "<li style=\"font-weight:$weight\">";
echo '<a href="?'.$type.'='.$name.'">';
echo '<i class="fa fa-file" style="margin-left:'.(10*$level).'px"></i>';
echo " $name</a>\n";
echo "</ul>";
echo '<p /><form><input name="grep"><input type="submit" value="Search"></form>';
<td width="75%" style="padding: 1em">
if ($_GET['dir']) {
if ($_GET['new']) {
mkdir("$datadir".$_GET['dir']) or die('fail');
die('<h3>CREATED DIRECTORY: '.$_GET['dir']. " <a href=\"$myurl\">continue</a></h3>");
echo '<h3>You have selected the '.$_GET['dir'].' directory</h3>';
echo '<form method="GET">Create a file named: <input type="hidden" name="new" value="true"><input name="text" value="'.$_GET['dir'].'/"> <input type="submit" value="Go"></form>';
echo '<form method="GET">Create a directory named: <input type="hidden" name="new" value="true"><input name="dir" value="'.$_GET['dir'].'/"> <input type="submit" value="Go"></form>';
elseif ($_GET['text'])
if ($_GET['new'])
touch("$datadir".$_GET['text']) or die('fail');
die('<h3>CREATED FILE: '.$_GET['text']. " <a href=\"$myurl\">continue</a></h3>");
elseif ($_POST['edittext'])
file_put_contents("$datadir".$_GET['text'], $_POST['edittext']);
elseif ($_GET['delete'])
unlink("$datadir".$_GET['text']) or die('fail');
die('<h3>DELETED FILE: '.$_GET['text']. " <a href=\"$myurl\">continue</a></h3>");
if ($_GET['edit'])
echo '<h3> Editing file: '.$_GET['text'].'</h3>';
echo '<form method="POST" action="?text='.$_GET['text'].'"><textarea name="edittext" rows=30 cols=80>'.htmlentities(file_get_contents("$datadir".$_GET['text'])).'</textarea><input type="hidden" name="text" value="'.$_GET['text'].'">';
echo '<p><input type=submit value="Save"></p></form>';
echo '<h3> Displaying file: '.$_GET['text'].'</h3>';
echo '<h4> Options: <a href="?text='.$_GET['text'].'&edit=true">Edit</a> | <a href="?text='.$_GET['text'].'&delete=true">Delete</a></h4>';
$a = file_get_contents("$datadir".$_GET['text']);
if (strlen($a))
echo '<pre>'.htmlentities($a).'</pre>';
echo 'This file is empty';
elseif ($_GET['grep']) {
echo '<pre>';
echo passthru('grep -r '.escapeshellarg($_GET['grep']).' .');
echo '</pre>';
else {
echo '<h3>Please select a file or directory on the left</h3>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.