I saw a node answer; here's what you can do in PHP;
Create a new file called 'files.php' and put the following code in there:
<?php
// Specify the directory to scan for files
$dir = '/';
// Store the scandir results in a variable
$files = scandir($dir);
// Encode the array in JSON and echo it
echo json_encode($files);
?>
Save it and upload it to the directory you want to return the files from, make sure you specify the file path (you can modify the $dir with the path needed);
Now you can use JQuery for example to create a GET request to the files.php file we created and return the data back to the client,
<script>
$.get( "files.php", function( data ) {
console.log(data);
});
</script>
You'll see in the console the returned JSON containing all the file names from the result of the scandir; you can use these now to push into your UI, etc.