Jump to content

Random image script from a directory


DBookatay

Recommended Posts

Can someone please assist me. I found this script online, but need to modify it to only show 8 random (non repetitive) images, and keep failing.

  $dir = 'Albums/Kids/S/';
  $file_display = array ('jpg', 'jpeg', 'png', 'gif');
  $dir_contents = scandir($dir);
  shuffle($dir_contents);
  foreach ($dir_contents as $file) {
  $file_type = strtolower(end(explode('.', $file)));
  if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {
	 $thumbs .= '<img src="'.$dir.'/'.$file.'" alt="" />';
  }
  }

Link to comment
https://forums.phpfreaks.com/topic/273654-random-image-script-from-a-directory/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.