Simple PHP Random Image

Simple way to mix elements of an array made with glob() & shuffle() functions:

<?php
function randomize() {
$pics = glob("*.jpg");
shuffle($pics);
return $pics[0];
}
echo '<img src="/images/' . randomize() . '.jpg" alt="" />';
?>

In this case the elements are JPEG files.

Advertisement

~ by angrybee on December 25, 2007.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.