Can I insert all images in HTML from a folder with one line of code?

I have an img folder , and inside the folder I have 200 images. Do I have the opportunity to insert all the images into the displayed html pages 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>
+3
source share
2 answers

You must use a 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.'" />';
}
+5
source

If you think you can get away with a simple html line, then no, no.

I assume that theoretically you can do this on the client side by analyzing the directory list returned by the web server, but this is really a way to compromise this.

- , php . , , , alt title ( ).

, nifty php exif.

+2

Source: https://habr.com/ru/post/1772097/


All Articles