I'm very new with this. I need to make all of the random images below link to the same page. In other words I need to add a 'hotspot' to this script. The code below is how far I've got:

<?php 
$img_array = glob("images/Coupons/*.{jpg}",GLOB_BRACE); 
//Pick a random image from the array 
$img = array_rand($img_array); 
//Display the image on the page 
echo '<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />'; 
?>

Any help would be most appreciated.
Thanks!
~Marty

Recommended Answers

All 4 Replies

Everything looks good- you just forgot to add the tag to make the image a link. The only change I made was in line 6:

<?php 
$img_array = glob("images/Coupons/*.{jpg}",GLOB_BRACE); 
//Pick a random image from the array 
$img = array_rand($img_array); 
//Display the image on the page 
echo '<a href="whatever.php">'.'<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" /></a>';
?>

Fantastic! Thank you for your help TySkby.
I was on the right track I just had my (") and (') mixed up! :)

Cheers!
~Marty

Glad to help- good luck!

I have another modification to make to my Random Image Script and I'm hoping someone can help me with the puntuation. I need to add an [usemap="#Map"]to the code on line #7 below:

<?php 
//This will get an array of all the gif, jpg and png images in a folder 
$img_array = glob("/path/to/images/*.{gif,jpg,png}",GLOB_BRACE); 
//Pick a random image from the array 
$img = array_rand($img_array); 
//Display the image on the page 
echo '<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />'; 
?>

Thanks in advance for any help.
~Marty

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.