I'm trying to get all directory and sub directory list as a JSON object but I'm not getting any ideas on how to do that.
currently I'm reading like this
->test.php
$path = realpath('Question Papers');
$self_files = glob($path . '/*');
$recursive_files = glob($path . '/**/*');
$all_files = $self_files + $recursive_files;
echo json_encode($all_files);
-> output on my js page
JS: C:\xampp\htdocs\projects\Question Papers/2014.pdf
JS: C:\xampp\htdocs\projects\Question Papers/2015.pdf
JS: C:\xampp\htdocs\projects\Question Papers/2016.pdf
JS: C:\xampp\htdocs\projects\Question Papers/2017.pdf
JS: C:\xampp\htdocs\projects\Question Papers/2018.pdf
JS: C:\xampp\htdocs\projects\Question Papers/Aeronautical
JS: C:\xampp\htdocs\projects\Question Papers/Civil
JS: C:\xampp\htdocs\projects\Question Papers/Electrical
JS: C:\xampp\htdocs\projects\Question Papers/Civil/2017.pdf
JS: C:\xampp\htdocs\projects\Question Papers/Civil/2018.pdf
JS: C:\xampp\htdocs\projects\Question Papers/Electrical/2014.pdf
JS: C:\xampp\htdocs\projects\Question Papers/Electrical/2015.pdf
JS: C:\xampp\htdocs\projects\Question Papers/Electrical/2016.pdf
JS: C:\xampp\htdocs\projects\Question Papers/Electrical/2017.pdf
JS: C:\xampp\htdocs\projects\Question Papers/Electrical/2018.pdf
I'm expecting Something Like below
Question Papers {
Civil{2014.pdf,2015.pdf,2016.pdf,2017.pdf,2018.pdf},
Electrical{2014.pdf,2015.pdf,2016.pdf,2017.pdf,2018.pdf},
Aeronautical{2014.pdf,2015.pdf,2016.pdf,2017.pdf,2018.pdf}
}
Can any one help me on how to achieve this in php or javascript.