How can I iterate through files in Javascript

前端 未结 4 1841
小蘑菇
小蘑菇 2021-01-21 05:08

Is it possible to iterate through a collection of files in Javascript? I am writing a jQuery plugin that takes either an array of images or, I was hoping, a directory containin

相关标签:
4条回答
  • 2021-01-21 05:51

    If the directory is on the same domain, and your webserver is setup to show directory indexes, then you could use javascript to request the url and load it into the dom for data extraction. This is brittle, and doesn't sound like it would make for a good plugin, much less good for anything but a one off task. But, you could do it.

    The other suggestions of having serverside script output json or xml would be an improvement.

    0 讨论(0)
  • 2021-01-21 05:52

    You can't.

    You have to get the list from your server through JSON or XML. Because of this, you can't do this in any way with javascript on servers you have no control over. Also, access to client side files is actively avoided for security reasons.

    0 讨论(0)
  • 2021-01-21 05:59

    You should use server side language to provide array of images in JSON or similar. There is no way Javascript can access local files. That would be serious security issue.

    0 讨论(0)
  • 2021-01-21 05:59

    You would need to create a web service to fetch the list of files. You can't use ajax to directly fetch the directory listing because ajax calls are restricted to the domain.

    0 讨论(0)
提交回复
热议问题