Introduction
Union Database is "File Flat" database which is based on PHO nad JSON.
Union Database is MIT Licence
Union Database allows the following:
- REST API with JSON
- Create CRUD with JSON
- Add folder
- Add files
- Delete Files
- Delete Folder
- View Folders
- View files
- Rename folder
- Rename files
- Upload folder
- Upload file
- Export folder
- Export file
- Copy files
- Move files
- Edit files
Installation
Installation is very simple. You need to have XAMP, WAMP, LAMP,... server installed on your computer. It is necessary to insert the UNION DATABASE folder that you previously downloaded from this page into the folder from the server (htdocs, www, ..). After that, in the browser, you need to go to the following address: http://localhost/union_database You have started UNION DATABASE and when you are called, you need to log in with your username and the password is ADMIN. and after that you can work.
Login
Login allows you to log in to the Union database.
You can find more details about logging with explanation and code on the United CMS at the following address: United CMS documentation
hen we log in, we use the following code that allows us to identify the logged in user. The example is logged in by the admin, it is first checked whether it exists in the database, and then whether the username and password data are correct with that data in the database. If they are then you can log in and automatically go to the home.php page, if it does not stay on the login page index.php.
Login user
You can also find out more about sessions and logging in at JSON LOGIN, at the following address: Login User
<?php
session_start();
if (isset($_SESSION['user'])){
function uzmiUser(){
$uzmi = file_get_contents('user.json');
$test = json_decode($uzmi,true);
return $test;
}
$test = uzmiUser();
foreach($test as $vlada){
$_SESSION['user'] =$vlada['user'];
}
?>
JSON REST API
JSON REST API Representational state transfer (REST) is a de-facto standard for a software architecture for interactive applications that typically use multiple Web services. (source: Wikipedia).
You can find more details about REST API with explanation and code on the Web Service at the following address: Web Service
JSON CRUD Example
JSON CRUD is functionality that allows us: ADD, VIEW, EDIT and DELETE value.
You can find more details about JSPN CRUD with explanation and code on the Function 7 & Grid - F 7 JSON at the following address: F 7 JSON CRUD
JSON HTML5 Example
JSON HTML5 show how you can use JAVASCRIPT to extract data from the JSON database and display it in an HTML table.
JSON HTML5
//Classic table
<table id='table'>
<tr>
<th>GFG UserHandle</th>
<th>Practice Problems</th>
<th>Coding Score</th>
<th>GFG Articles</th>
</tr>
<script>
$(document).ready(function () {
//Get value form jsondata.json
$.getJSON("jsondata.json",
function (data) {
//student is value for data acquisition
var student = '';
$.each(data, function (key, value) {
student += '<tr>';
student += '<td>' +
//value of sector
value.sector + '</td>';
student += '<td>' +
//value of NoOfProblems
value.NoOfProblems + '</td>';
student += '<td>' +
//value of TotalScore
value.TotalScore + '</td>';
student += '<td>' +
//value of Articles
value.Articles + '</td>';
student += '</tr>';
});
$('#table').append(student);
});
});
</script>
</section>
</table>
Add folder
Form
<form action="a_fo.php" method="post">
<h2>Add Folder:</h2>
<form action="a_fo.php" method="post">
<div class="form-group">
<label for="folder"><h2>Folder name:</h2></label>
<input type="text" id="folder" class="form-input" name="folder">
</div>
</form>
Action
<?php
if (isset($_POST['ubaci'])) {
//$baza=$_POST['baza'];
$folder=$_POST['folder'];
mkdir("$folder");
header("Location: home.php");
}else {
echo "ERROR";
}
?>
Add files
Form
<form action="a_fi.php" method="post">
<div class="form-group">
<label for="files"><h2>Files name:</h2></label>
<input type="text" id="files" class="form-input" name="files">
</div>
<div class="form-group">
<label for="pk_id"><h2>Folders</h2></label>
<div>
<select name="folder" id="folder" class="form-input">
<?php
$dirs = array_filter(glob('*'), 'is_dir');
foreach ($dirs as $value) {
echo "<option value='$value'>$value</option>";
}
?>
</select>
</div>
</div>
<br>
<div class="btn-group">
<button class="btn-2" type="submit" name="ubaci">Add file</button>
</div>
</form>
Action
<?php
if (isset($_POST['ubaci'])) {
$folder=$_POST['folder'];
$files=$_POST['files'];
$dir = "$folder";
$file_to_write = "$files";
if( is_dir($dir) === false )
{
mkdir($dir);
}
$file = fopen($dir . '/' . $file_to_write,"w");
fclose($file);
include $dir . '/' . $file_to_write;
header("Location: home.php");
}else {
echo "ERROR";
}
?>
Delete Files
Form - select folder
<form action="delete.php" method="post">
<div class="form-group">
<label for="folder"><h2>Folders</h2></label>
<div>
<select name="folder" id="folder" class="form-input">
<?php
$dirs = array_filter(glob('*'), 'is_dir');
foreach ($dirs as $value) {
echo "<option value='$value'>$value</option>";
}
?>
</select>
</div>
</div>
<div class="btn-group">
<button class="btn-2" type="submit" name="ubaci">Delete</button>
</div>
</form>
Form - select file
<form action="d_fi.php" method="post">
<div class="form-group">
<label for="files"><h2>Files</h2></label>
<div>
<select name="files" id="files" class="form-input">
<?php
if (isset($_POST['ubaci'])) {
$folder=$_POST['folder'];
if ($handle = opendir("$folder")) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo "<option value='$folder/$entry'>$folder/$entry</option>";
}
}
closedir($handle);
}
}
?>
</select>
</div>
</div>
<div class="btn-group">
<button class="btn-2" type="submit" name="ubaci">Delete</button>
</div>
</form>
Action
<?php
if (isset($_POST['ubaci'])) {
$files=$_POST['files'];
unlink($files);
echo "<script>alert('Delete!')</script>";
echo "<script>window.history.go(-2);</script>";
}
?>
Delete Folder
Form
<form action="d_fo.php" method="post">
<div class="form-group">
<label for="pk_id"><h2>Delete Folders</h2></label>
<div>
<select name="folder" id="folder" class="form-input">
<?php
$dirs = array_filter(glob('*'), 'is_dir');
foreach ($dirs as $value) {
echo "<option value='$value'>$value</option>";
}
?>
</select>
</div>
</div>
<br>
<div class="btn-group">
<button class="btn-2" type="submit" name="ubaci">Add folder</button>
</div>
</form>
Action
<?php
if (isset($_POST['ubaci'])) {
$folder=$_POST['folder'];
$dir = "$folder";
foreach($dir as $f) {
if ($f->isDir()){
rmdir($f->getRealPath());
} else {
unlink($f->getRealPath());
}
}
header("Location: home.php");
rmdir($dir);
}else {
echo "ERROR";
}