Know how many images or files you have in a folder

Asked

Viewed 35 times

1

I am developing a project in Laravel and I made a section where will show background images every 2 seconds.

My code js for you to have an idea.

const career = document.getElementById('career');
var index = 1;

function changeBackgroundImage(){
  index += 1;
  if(index < 4){
      career.style.backgroundImage = `url('../../../images/pages/index/career/${index}.jpg')`;
  }else{
      index = 1;
      career.style.backgroundImage = `url('../../../images/pages/index/career/${index}.jpg')`;
  }
}
setInterval('changeBackgroundImage()', 2000)

I was wondering how do I javascript to count how many images there are inside this folder.

1 answer

1


This is not possible using Javascript only!

You can make an Ajax call to a page that accesses the folder on the server and returns the expected result, but it is important to remember that the folder must not be in the client machine.

Reference: https://stackoverflow.com/a/1266009/5626568

  • 1

    Thank you very much for your reply.

  • 1

    I appreciate the feedback and I’m glad I could help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.