I have a function to load an image in a js file.
It loads images from 1.jpg to the specified number (say, 20).
What I would like to do instead of specifying a number is to find out how many images are in the folder, and then use this as the specified number.
I know that it is possible to use GLOB in PHP, but AFAIK you cannot use PHP in a js file?
function loadpics(url){
var txt,i,j;
j=20
//j=count(glob("images/" + url + "/*",GLOB_BRACE)); PHP file count here.
txt= "<span id=\"lar\">«</span><img id=\"main-img\" src=\"images/" + url + "/1.jpg\"/><span id=\"rar\">»</span><div id=\"scroller\">";
for (i=1;i<j;i++)
{
txt += "<img src=\"images/" + url + "/t/" + i + ".jpg\"/>";
}
document.getElementById("sidebar-b").innerHTML=txt + "</div>";
}
So, how can I get the number of files from the URL that I pass to the image upload function?
Or is there a better way?
source
share