tags:

views:

45

answers:

2

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>
+5  A: 

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.'" />';
}
infinity
+2  A: 

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