Javascript支持获取目录列表的能力吗? [英] Does Javascript support the ability to get a directory listing?

查看:152
本文介绍了Javascript支持获取目录列表的能力吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一堆图像文件上传到我在ISP的免费托管服务上设置的目录中。这就像 http://home.ISPname.net/~username/subdir 。 p>

我希望我的Javascript代码能够获取目录列表,然后预加载所发现的任何内容。

但是有可能获得这样的事情吗?我的印象不是。



我怀疑我将不得不将我的文件重命名为00000.jpg并向上,并尝试使用try尝试检测哪些文件。



仅供参考,我知道我的ISP不支持使用FTP协议来获取目录列表。



感谢您的帮助。 >

解决方案

假设您的JavaScript代码是您的网页上的代码,而不是您的服务器上的代码,那么不,没有API提供用于浏览器中的JavaScript ,而不是通过您可以自行创建的HTTP访问的服务器端API。如果包含文件的目录位于服务器上,那么它必须是一些服务器端代码,无论如何都要提供目录列表。您可以在您选择的服务器端编程环境中编写这样的代码(包括服务器端JavaScript解决方案,如果这是您想要的,并且您的ISP可能有这种情况)。正如Pekka所指出的那样,简单地在服务器上启用目录浏览功能可能是可能的,尽管这通常是一种相当低级的服务,它会为您提供某种类型的HTML页面,并且通过解析可能会有些痛苦(与您的相比可以从定制的服务中获得)。

另一个更简单的方法是将清单文件与其他图像文件一起上传。换句话说,以易于摘要的形式创建目录列表,并将其单独保存为一个简单的文件以供读取。


I want to upload a bunch of image files to a directory that I've set up on my ISP's free hosting service. It's something like http://home.ISPname.net/~username/subdir.

I want my Javascript code to be able to get a directory listing and then preload whatever it finds.

But getting such a thing even possible? My impression is not.

I suspect I will have to instead rename my files to 00000.jpg and upward, and attempt to detect what files are there using try.

FYI, I know that my ISP does not support using FTP protocol to get a directory listing.

Thanks for any help.

解决方案

Under the assumption that your JavaScript code is code on your pages and not code on your server, then no, there's no API provided for JavaScript in a web browser other than a server-side API accessible via HTTP that you would create yourself. If the directory full of files is on the server, then it's going to have to be some server-side code that delivers the directory listing anyway. You could write such code in the server-side programming environment of your choice (including a server-side JavaScript solution, if that's what you want and if such a thing is possible at your ISP). As Pekka notes, it may be possible to simply enable directory browsing in your server, though that's generally a fairly low-level service that will deliver some sort of HTML page to you, and parsing through that might be somewhat painful (compared to what you could get from a tailor-made service).

Another, simpler thing you could do would be to upload a manifest file along with the other image files. In other words, create the directory listing in some easy-to-digest form, and maintain it separately as a simple file to be fetched.

这篇关于Javascript支持获取目录列表的能力吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆