0

I tried searching for an answer to this question, but all I encountered were how to allow users to upload files.

So what I want to do is run a for loop over all the files within a local file to obtain the path of each file. Is there a way to do this?

Edasaur
  • 397
  • 1
  • 8
  • 19

1 Answers1

1

You cannot directly. It will be a big security hole to allow JS to browse local directory...

Cyril ALFARO
  • 1,616
  • 17
  • 35
  • Maybe I'm not being clear with my terms. When I was referring to 'local directory', I meant the files that I upload along with my html, css, and javascript files on the server. – Edasaur Mar 21 '14 at 23:58
  • What is your goal ? Will be easier like this :). – Cyril ALFARO Mar 22 '14 at 00:00
  • You want to see an a page the absolute path of some files ? Why you speak about javascript ? You use nodejs ? – Cyril ALFARO Mar 22 '14 at 00:01
  • Ah okay. So I have a directory of images that are located in another folder from my javascript file and I want to take all those images and insert them dynamically onto a webpage. The reason I wanted to search within the directory of images for files rather than hard coding each image is that I figured that writing a script to search for images would reduce clutter in my code. – Edasaur Mar 22 '14 at 00:02
  • Ok but Javascript is frontend stuff (if you dont use nodejs) and what you want to do is to list files hosted on server. Why dont use backend language like PHP ? – Cyril ALFARO Mar 22 '14 at 00:05
  • Because I'm not familiar with PHP or any other backend languages :P – Edasaur Mar 22 '14 at 00:08
  • Is there no other way to go about this other than through backend? – Edasaur Mar 22 '14 at 00:08
  • 1
    Frontend is fully editable by users. And of course you dont want user browse your server directory so no you cannot. But you can think about renaming your images from 001.jpg to 100.jpg for example and iterate on them whith JS until a 404 error appear. – Cyril ALFARO Mar 22 '14 at 00:09
  • If I answer your request please tag my responce :) – Cyril ALFARO Mar 22 '14 at 00:14