Log in

View Full Version : Resolved php random image



john1991
11-15-2010, 03:29 AM
Hi all,

I am trying to generate a random image form file within a list item.

I am missing something but trying to figure it out, here is my code I am working with:


<!-- bg img -->
<?php
$images = array(

array('file1' => 'bg',
'caption' => ''),

array('file2' => 'bg2',
'caption' => ''),

);
$i = rand(0, count($images)-1);
$selectedImage = "img/{$images[$i]['file1'] ['file2']}.jpg";
$caption = $images[$i]['caption'];
if (file_exists($selectedImage) && is_readable($selectedImage)) {
$imageSize = getimagesize($selectedImage);
}
?>
<div class="jbgallery">

<ul>
<li><a href="<?php echo $selectedImage; ?>">1</a></li>
<li><a href="<?php echo $selectedImage; ?>">2</a></li>
</ul>

</div>
<!-- end -->

Thank you for any help and suggestions.

Nile
11-15-2010, 01:03 PM
Are you trying to make the list of images in a random order? Or one random image the same for every list item.