Commit f799d0c7 authored by Gudipaty Aniket's avatar Gudipaty Aniket

Added directory tree backend

parent 1bf37d71
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Content-Type: application/json; charset=UTF-8");
$postData = file_get_contents("php://input");
$postData = json_decode($postData, true);
$uname = $postData['username'];
function dirToArray($dir)
{
$result = array();
$result["dirs"] = array();
$result["files"] = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result["dirs"][$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value);
}
else
{
array_push($result["files"], $value);
}
}
}
return $result;
}
$Dir = "../users/" . $uname;
echo json_encode(dirToArray($Dir));
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment