Here is the php script (sorry, lots of comments for learning purposes):
<?
//Directory the images are stored relative to root.
$imgdir = '/home/aenigma/public_html/vyx/media/images/header';
//Path to images folder
$dirpath = '/media/images/header/';
//Create an array with the list of files as each value.
//Keep in mind, the first two values listed for a directory
//will always be: "." and ".." UNLESS you change the
//sort order.
$dirlist = scandir($imgdir);
//Count the number of items in the array "dirlist"
//Basically, count how many files are in the directory.
//We subtract 1 from this because it counts the "0" value
//in teh array as 1.
$dircount = count($dirlist) - 1;
//Get a random number between 2 and the size of the array.
$randnum = mt_rand(2,$dircount);
//When you create an array, every entry into the array
//is assigned a value 0-128. When we create a random number
//between 2 and the maximum number of values in the array,
//we're essentially picking which value to call from teh array.
//This next part uses our random value as the entry to call from
//the array.
$imgname = $dirpath . $dirlist[$randnum];
//Now we just tell php to show the image.
echo "<img src='$imgname'></img>";
?>
Here is the HTML:
<table width="600" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><a href="http://link.com"><img src="<? include('scripts/randimg.php'); ?>" width="600" height="150" border="0"></a></td>
</tr>