Mark Szymanski
Mark Szymanski

Reputation: 58060

Loop through directory with images with Javascript

Is there any way to loop through a directory full of images (or any type of file, for that matter) with Javascript?

EDIT: The directory is on the server. Sorry for the confusion.

Upvotes: 2

Views: 7883

Answers (3)

gion_13
gion_13

Reputation: 41533

No.
If there was, it would've been a major security problem : anyone could have gain access to (your) the server's hard-disk through any browser.
It is possible to implement a Directory/File parser in other server-side languages and return its result through ajax.

Upvotes: 2

wajiw
wajiw

Reputation: 12269

You can't do directory actions directly through javascript. What you can do though is name your files in order and check based on the name. Like if your names are Image1.png, Image2.png you can make a js loop that creates Image objects based on that number increment and check if it loaded using an onload function.

Upvotes: 1

g.d.d.c
g.d.d.c

Reputation: 47988

JavaScript does not have access to the file system directly. If you do not know what the names of the files are you have to generate the list with some higher level scripting language like PHP.

As I say that, there is an off chance that, if you had directory browsing enabled on the directory in question, that you could attempt to retrieve that directory via an AJAX call and then parse the results. I haven't ever tried, but it may be possible.

Upvotes: 1

Related Questions