3

I have folder img and inside of the folder I have 200 pictures. Do I have any possibility to insert all the images in a html pages to be shown, without writing this line of code 200 times?

<img src="img/ladybug.jpg" alt="Ladybug" title="Ut rutrum, lectus eu pulvinar elementum, lacus urna vestibulum ipsum"></li>
Peter
  • 31
  • 1
  • 2
  • You don't need to **write** much with the advent of state-of-art tools such as webstorm :) http://www.jetbrains.com/webstorm/ – Sarfraz Oct 29 '10 at 11:19
  • 2
    Where do you get the content of the alt and title tag from? – Bernd Oct 29 '10 at 11:26
  • 1
    Doesn't matter. I just want the picture to appear on the webpage. Is something personal. – Peter Oct 29 '10 at 11:47
  • Tell the truth: you are an avid Bash user who wants a `*` glob analogue (I am! :-)). Js version: http://stackoverflow.com/questions/18480550/how-to-load-all-the-images-from-one-of-my-folder-into-my-web-page-using-jquery – Ciro Santilli OurBigBook.com Oct 11 '15 at 10:14

2 Answers2

6

You have to use server side language such as PHP or ASP

PHP example:

$dir    = '/images';
$files = scandir($dir);
$images = array();
foreach($files as $file) {
  if(fnmatch('*.jpg',$file)) {
    $images[] = $file;
  }
}

foreach($images as $image) {
  echo '<img src="images/'.$image.'" />';
}
Alex Rashkov
  • 9,833
  • 3
  • 32
  • 58
2

If you think you can get away with a simple line of html, then no, that's a no-go.

I guess theoretically you could do it client side, by parsing the directory listing returned by the webserver, but that's really way to complex to handle this.

The only reasonable way is to do it server side using php or the likes. The problem you'll be stuck with though, is that a pure directory listing doesn't contain enough information to get values for alt and title (which is what Bernd was getting at).

I suppose with some nifty php, you could get those out of exif though.

Joeri Hendrickx
  • 16,947
  • 4
  • 41
  • 53