Results 1 to 2 of 2

Thread: php random image

  1. #1
    Join Date
    Nov 2010
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default php random image

    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:

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

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

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

      );
    $i rand(0count($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.
    Last edited by john1991; 11-15-2010 at 05:38 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Are you trying to make the list of images in a random order? Or one random image the same for every list item.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •