/ Published in: PHP
Put your images in a folder called 'random' in your ROOT directory.
Please this script at the top of your page:
Please this script at the top of your page:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function RandomFile($folder='', $extensions='.*'){ // fix path: $folder = ($folder == '') ? './' : $folder; // check folder: // create files array // open directory // go trough all files: // feed the array: $files[] = $file; } } // close directory } else { } } // seed random function: // get an random index: // check again: } // return the random file: return $folder . "/" . $files[$rand]; } $random1 = RandomFile("random"); while (!$random2 || $random2 == $random1) { $random2 = RandomFile("random"); } while (!$random3 || $random3 == $random1 || $random3 == $random2) { $random3 = RandomFile("random"); } while (!$random4 || $random4 == $random1 || $random4 == $random2 || $random4 == $random3) { $random4 = RandomFile("random"); } ?> // place this section where you'd like to display the images: <div id="random_images"> <img src="/<?php echo $random1; ?>" alt="image alt" /> <img src="/<?php echo $random2; ?>" alt="image alt" /> <img src="/<?php echo $random3; ?>" alt="image alt" /> <img src="/<?php echo $random4; ?>" alt="image alt" /> </div>