I’d like to count the number of files in a folder and return that number to set a variable in a .js file.
Essentially, I have X number of images in a folder. When the user clicks the right arrow, I replace the existing set of 8 images with the next set of 8 images, and so on and so forth. I currently manually enter the variable (38 right now) into the page, since there are 38 thumbnails in the folder.
The code works perfectly, but I hate the idea of changing a number each time I add a file. I’d like to have it set the variable to the exact number of images in the folder.
Is this possible using JavaScript or jQuery? Do I need to write a PHP file to do return this variable for me? Any information would be great!
This is the kind of task PHP is better suited for, keep your Javascript to the client-side. Write a very simple PHP script that counts the files in a folder
And call it from your JQuery script.