I need to get array of all images (or simply of all files) in directory (e.g. www.example.com/images/). I prefer to use JavaScript but it's hard to make. So should I use PHP, meybe?
Could you please help me - I'm not good at this.
Thank you very much!
I managed to do it in base javascript using a modifyed ajax command to get the folder list as an html file. Then I grep the file names from inside of it:
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// gets the entire html file of the folder 'logpost' in this case and labels it thing
thing = this.responseText
searchFor = /.html</g
a=0;
b=0;
var str = "";
// greps file for .html and then backs up leter by letter till you hot the file name and all
while ((dothtmls = searchFor.exec(thing)) != null ){
str = "";
console.log(dothtmls.index);
a = dothtmls.index;
while (thing[a] != '>' ){
a--;
}
a++;
while(thing[a] != '<'){
str = str + thing[a];
a++;
}
console.log(str);
}
}
};
xhttp.open("GET", "logpost/", true);
xhttp.send();
}
This is probably not the cleanist way but if you are working on a static web sever it should work :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With