Loading images from a directory with PHP

This is how you can use PHP to display all of the images in a directory (folder) where the PHP page lives.

<?php
$files = glob("*.jpg");
$fileCount = count($files);
for ($i = ($fileCount-1); $i >= 0; $i--) {
  echo '<img src="' . $files[$i] . '"><br />';
}
?>


Note: this will only display images with the extension .jpg. You will have to modify it to display other image types (png, gif, etc.).

Leave a comment

Your email address will not be published. Required fields are marked *