扫描Java脚本中的文件夹内容

人气:372 发布:2022-10-16 标签: html javascript video html5-video

问题描述

我正在尝试构建一个HTML5视频播放器,如果/Video文件夹中有多个视频文件,该播放器将自动打开播放列表模式。

我正在尝试不使用PHP,因此在提出建议时请记住这一点。

谢谢。

推荐答案

不能使用JAVASCRIPT访问文件系统。但是,您可以对具有索引访问权限的目录执行虚假的HTTP请求:

var dir = "/videos";
var fileextension = ".mp4";
$.ajax({
    //This will retrieve the contents of the folder if the folder is configured as 'browsable'
    url: dir,
    success: function (data) {
        // List all mp4 file names in the page
        $(data).find("a:contains(" + fileextension + ")").each(function () {
            var filename = this.href.replace(window.location.host, "").replace("http:///", "");
            $("body").append($("<img src=" + dir + filename + "></img>"));
        });
    }
});

644