-1

I want to create a page that can add any of the files added to a specific folder to a list, as a link that will be able to open the file. Is there a way to do this without typing out each file name in a list with a link?

Right now I need to add each file as <li><a href="fileName.pdf"> File Name<a><li> but I would need to add more code every time a file is added.

Is this even possible?

isherwood
  • 58,414
  • 16
  • 114
  • 157
  • This is generally a backend (server-side) operation. Modern browser security usually disallows it. – isherwood Feb 17 '22 at 16:50
  • You could also code a simple loop with an array, so that you'd just add the new filename to the array rather than writing markup. It's a small efficiency enhancement, but could be worth doing. – isherwood Feb 17 '22 at 16:51

1 Answers1

-1

You can't do this with pure js. You can do ajax call but that's it. You'll still need to do some backend coding.

Add

Options +Indexes

to .htaccess and then link the actual folder.

Or even better use PHP to get all files in folder and echo them!

pepeD
  • 155
  • 16
  • You can do this with pure JS. You can use a JavaScript-based backend like Node.js or Deno. Why are you assuming the OP uses Apache httpd and PHP is an option? What if the OP uses Nginx, Lighttpd, or Java Spring based backend? There is no support for `.htaccess`. – jabaa Feb 17 '22 at 16:53
  • @jabaa He didn't specified if he is using backend JS or client side JS. And I assume he is using client side JS, because when you look at his profile he have also questing about js. Maybe it's just a bad guess. We'll see, if the OP responds. – pepeD Feb 17 '22 at 16:58