Scan folder content in Javascript
12,233
You cannot access file-system using JavaScript. But, you can do a fake HTTP request to the directory with index access:
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>"));
});
}
});
Author by
diederik
Updated on June 04, 2022Comments
-
diederik almost 2 years
I am trying to build an HTML5 video player that will automatically turn on playlist mode if there is more than one video file in the /videos folder.
I'm trying not to use PHP for this so please keep that in mind when suggesting something.
Thank you.