扫描 Javascript 中的文件夹内容
Scan folder content in Javascript
我正在尝试构建一个 HTML5 视频播放器,如果 /videos 文件夹中有多个视频文件,它会自动打开播放列表模式。
我尽量不为此使用 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>"));
});
}
});
我正在尝试构建一个 HTML5 视频播放器,如果 /videos 文件夹中有多个视频文件,它会自动打开播放列表模式。
我尽量不为此使用 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>"));
});
}
});