Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- show-images-random-order.php
- Show all images in a directory in a random order
- Example: when you need to show many logo of important institutions & you want to avoid anyone getting upset over the order of the logo is shown. Yup, real story.
- credit : DaveRandom = https://stackoverflow.com/a/12666210/882002
- */
- $dir = $_GET['loc'];
- $file_display = array ('jpg', 'jpeg', 'png', 'gif');
- if (file_exists($dir) == false) {
- echo 'Directory \'', $dir, '\' not found';
- } else {
- $dir_contents = scandir($dir);
- shuffle($dir_contents);
- echo '<center>';
- foreach ($dir_contents as $file) {
- $file_type = strtolower(end(explode('.', $file)));
- if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {
- echo ' <img style="max-width: 200px; height: auto; border-width: 25px; border-color: white; border-style: solid;" class="photo" src="', $dir, '/', $file, '" alt="', $file, '" /> ';
- }
- }
- echo '</center>';
- }
- ?>
Add Comment
Please, Sign In to add comment