Listing files of a directory in a webpage

2019-01-19 14:50发布

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

I would like to upload some PDF files to certain directory of my static website (html + js), and want to show the list of the files in a page with the link to view the pdf files so that if i upload new files i don't have to modify the html page every time, is there any way to do that ?

7条回答
虎瘦雄心在
2楼-- · 2019-01-19 15:42
  1. Open a browser
  2. Navigate to the folder you want listed
  3. If you see a list of the files, continue
  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);
});
查看更多
登录 后发表回答