Javascript列出Web服务器上目录中的所有文件 [英] Javascript to list all files in directory on the webserver

查看:417
本文介绍了Javascript列出Web服务器上目录中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在服务器端语言中执行此操作,但我想知道是否有一种简单的方法(如没有活动X)。谷歌搜索只为我提供了javascript从用户计算机列出文件的方法。

I know how to do this in server side languages but I was wondering if there is an easy way (as in no active X). Google searches only give me ways for javascript to list files from the user's computer.

如何使用javascript列出服务器上的所有文件。也就是说,如果我有一个文件夹/ gallary,那里可以有很多子导演,/ gallary / sports,/ gallary / california,/ gallary / christmas。每个子目录包含n个图像。

How can I use javascript to list all files on the server. That is, if I have a folder /gallary and there can be many sub-directors in there, /gallary/sports, /gallary/california, /gallary/christmas. Each sub-directory contains n image.

如何让javascript列出所有子目录以及所有图像。

How can I get javascript to list all sub-directories as well as all the images.

推荐答案

由于浏览器中的javascript无法直接访问服务器的文件系统,您可能需要一些服务器端脚本,如PHP,Perl,ASP等来发送文件系统内容到一个网页(也许通过Ajax),然后将文件系统内容的javascript格式化为所需的格式,比如在这个答案中使用文件树控件提及:https://stackoverflow.com/a/9057959/74585

As javascript in the browser cannot access the server's file system directly you are probably going to need some server side scripting such as PHP, Perl, ASP etc to send the file system contents to a web page (perhaps via Ajax) and then have javascript format the file system contents into the desired format, say using a file tree control mention in this answer: https://stackoverflow.com/a/9057959/74585

如果你不能使用任何服务器端脚本那么也许你可以硬编码javascript文件中的类别(假设类别不经常更改),并按顺序编号图像?然后你的javascript可以通过尝试加载图像类别文件夹和数字来寻找图像。然后检测图像何时没有通过onrorror加载并停止显示上一个/下一个按钮。

If you can't use any server side scripting then perhaps you could hardcode the categories in the javascript file (assuming the categories change not very often), and number the images sequentially? Then your javascript can just go looking for images by trying to load an image category folder and number. Then detect when an image doesn't load via onerror and stop display previous/next buttons.

一个不需要服务器端脚本的更左边的字段解决方案可能是在您的通过FTP连接的工作站计算机上创建一个脚本(例如perl),查看所有文件夹和文件,并创建包含文件系统内容的JSON或XML文件。然后你的javascript可以调用生成的文件并访问文件系统。缺点是每次要添加其他文件时都需要重新运行工作站脚本。

An even more left field solution which doesn't require server side scripting could be to create a script, say with perl, on your workstation machine which connects over FTP, looks through all the folders and files and creates a JSON or XML file containing the contents of the file system. Then your javascript can call that generated file and get access to the file system. The drawback being that you need to rerun your workstation script each time you want to add another file.

这篇关于Javascript列出Web服务器上目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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