vendredi 2 juillet 2021

How to List the Files in a Server side directory

I am a newbie on web development. Trying to list all the files in a specific directory on the server side when onClick interaction from user. Is it possible to serve files in a directory at server side? As far as I got it may not be possible on client side. But as a newbie I wanted to ask to community.

<button onclick="someGreatFunction()">btn</button>

  <script>
    function someGreatFunction() {
             //TODO: list all files in a directory
  
     }
    </script>

What I have done ;

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"><!--  JQUERY  -->

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
  </script>
  <title></title>
</head>
<body>
  <h1>Listing /somedir</h1><!-- Custom Script (defered load, after dom ready) -->
  <script>
    $.getJSON('./somedir', data => {
        console.log(data); //["doc1.jpg", "doc2.jpg", "doc3.jpg"] 
    });
  </script>
</body>

ref




Aucun commentaire:

Enregistrer un commentaire