I have written this script to display on the webpage random images from a directory on server. The directory contains plenty of images.
On the Event of Mouseover and MouseOut, I should get different images.
It doesnot work, I only get the 1st image, and then Rollover does not take place.
What's wrong in the script ?
The script:
<head>
</head>
<body>
<?
// Directory goes here relative to script
$image_catalog = 'images';
// Directory should contain only images...
$i = 0;
$allimages = opendir ($image_catalog);
while ($f = readdir($allimages))
{ if ($f != '.' && $f != '..')
// Directory should contain only images...
{$imageArray[$i++] = $f;}
}
closedir ($allimages);
?>
<?
srand((double)microtime()*1000000);
?>
<script languge="javascript">
function displayMyimage(img) {
<?
$imageName = $image_catalog.'/'.$imageArray[rand(0,sizeof($imageArray)-1)];
$imageProperties = GetImageSize ($imageName);
$dimensions = ereg_replace("\"", "'" , $imageProperties[3]); // 3rd Element contains width="xxx" height="xxx"
?>
if (document.images)
document[img].src = "<? echo $imageName ?>";
}
</script>
<P><img name='myImage' src=<? echo $imageName ?> <? echo $dimensions ?> align=left onMouseOver="displayMyimage('myImage')" onMouseOut="displayMyimage('myImage')"></p>
</body>
End of script
Any idea, how can i achieve this random display of Images on mouse events and PHP ?
Thank you for help.
Brij.