Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing files of a directory in a static webpage

Is there any way to list the files of a directory in a static webpage with the link to view the file?

I would like to upload some PDF files to a certain directory of my static website (it uses HTML and JS), and want to show the list of the files in a page with the link to view the pdf files. That way, if I upload new files, I don't have to modify the HTML page every time. Is there any way to do that?

like image 787
B.M. Avatar asked Jan 09 '15 12:01

B.M.


People also ask

Is it possible to get a list of files under a directory of a website?

How Do I Get All Files From A Website? The easiest way to search web directory is to connect to the webserver via SSH or RDP and run the command to output the list of local directories.

How do I list files in a directory in html?

Use the dir tag in HTML to display directory list.

How can I see my website directory listing?

Usually you go to http://example.com and it shows you the file "index. html". But for example, oftentimes if there is a file at http://example.com/images/picture.jpg then you could go to http://example.com/images/ and the site would show you the directory /images/ and all the files inside.


2 Answers

If you are using Apache as a web-server and have configured mod-autoindex for the directory you upload pdf files then you should probalby see somethink like this when navigation to that url:

enter image description here

This auto-generated page can be easily parsed by js using jquery:

var pdfFilesDirectory = '/uploads/pdf/';

// get auto-generated page 
$.ajax({url: pdfFilesDirectory}).then(function(html) {
    // create temporary DOM element
    var document = $(html);

    // find all links ending with .pdf 
    document.find('a[href$=.pdf]').each(function() {
        var pdfName = $(this).text();
        var pdfUrl = $(this).attr('href');

        // do what you want here 
    })
});
like image 156
Olim Saidov Avatar answered Sep 26 '22 12:09

Olim Saidov


  1. Open a browser
  2. Navigate to the folder you want listed
  3. If you see a list of the files, continue
    • If you don't see a list of the files, Take a look at this: Is it possible to get a list of files under a directory of a website? How? to figure out how to do that.
  4. Make an ajax call to that folder (example below)
  5. response will be the html of the listing page
  6. You can parse that out to get the file listing

Example:

// This is in angular, but you can use whatever
$http.get('folder_to_list/').success(function(response) {
    console.log(response);
});
like image 38
Travis Heeter Avatar answered Sep 24 '22 12:09

Travis Heeter