0

I created a HTML page.

Now, I try to display all the pictures that are in a specific folder (/folder1) in this HTML page (Note: I don't know the names of these images).

I try to create a loop, which read all this images, and display it in this HTML.

There is an easy way to do that?

2
  • 1
    If you don't know the names, then you'll need to use a server-side language asp.net or PHP for example, to scan the directory and add all the images to an array that you can iterate through. HTML is just markup. Commented Nov 26, 2013 at 13:16
  • An alternative would be to look at the settings on the actual website to allow users to browse directories. In IIS the setting is called 'Directory Browsing'. It's probably similar in Apache or Tomcat. Commented Nov 26, 2013 at 13:20

3 Answers 3

3

You are looking for something which HTML cannot do. You are going to need some sort of backend language, whether that be Rails, PHP, Python, or something else doesn't really matter.

HTML is and always will be only a Markup Language.

Here is a similar post which has code that might help you:

How To Display All Images in Folder

Sign up to request clarification or add additional context in comments.

Comments

1

With php you can use function scandir() to retrieve all the files in a directory, and save them as an array.

Then iterate over that array and display any image with something like:

echo '<img src="path/to/folder1/'$files_array[i]'">

where $files_array contains the names of every image file in that directory.

Comments

0

if your images are stored in a server you can read the directory and get the image name them send to the font end.

if you are work in a local file system such as

/dir/index.html
/dir/images/
/dir/images/xxx.png
/dir/images/aaa.png
/dir/images/other  image.png

you can rename all images in batch to 1.png 2.png 3.png ...and so on then use javascript in html to

generate the image

var body = document.getElementsByTagName("body")[0];
for (var i = 0; i < 100; ++i) {
  var img = document.createElement("img");
  img.src = "images/" + i + ".png";
  body.appendChild(img);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.