Jump to content

rotator.php broke when my host upgraded to PHP 5


melissam

Recommended Posts

I used rotator.php for well over a year to rotate image links on my website. Then, my host upgraded to PHP 5 and it broke! Here is the code:

 

<?php

  # file containg your image descriptions

  $IMG_CONFIG_FILE = 'images.ini';

  # You shouldn't need to change anything below this point

  function showImage( $ini=null ) {
    global $IMG_CONFIG_FILE;
    # if no custom ini file has been specified, use the default
    $ini_file = $ini ? $ini : $IMG_CONFIG_FILE;
    # read the config file into an array or die trying
    $images = @parse_ini_file($ini_file,true);
    if (! $images) {
      die('Unable to read ini file.');
    }
    # pick a random image from the parsed config file
    $img = array_rand($images);
    # get the selected image's css id if one exists
    $id = $images[$img]['id'] ?
      sprintf( ' id="%s" ', $images[$img]['id'] ) :
      '';
    # get the selected image's css class if one exists
    $class = $images[$img]['class'] ?
      sprintf( ' class="%s" ', $images[$img]['class'] ) :
      '';
    # get selected image's dimensions
    $size = @getimagesize( $images[$img]['src'] );
    # if an url was specified, output the opening A HREF tag
    if ( $images[$img]['url'] ) {
      printf(
        '<a href="%s" title="%s">',
        $images[$img]['url'],
        $images[$img]['title']
      );
    }
    # output the IMG tag
    printf(
      '<img src="%s" alt="%s" %s %s%s/>',
      $images[$img]['src'],
      $images[$img]['alt'],
      $size[3],
      $id,
      $class
    );
    # if an url was specified, output the closing A HREF tag
    if ( $images[$img]['url'] ) {
      echo('</a>');
    }
  }


?>

 

First I got an error telling me it was unable to read the ini file - this was the only text on a blank screen, none of my content was visible. I changed this:

 

    if (! $images) {
      die('Unable to read ini file.');
    }

 

to this:

 

 if (!isset($images)) {
      die('Unable to read ini file.');
    }

 

and the rest of my page showed up fine. I was just left with an error message in my rotate box: "Warning: array_rand() [function.array-rand]: First argument has to be an array in (url withheld) on line 44"

 

Line 44 is this line:  $img = array_rand($images);

 

...if that helps.

 

Does anyone know why this is not working? I'm afraid I'm not much of a coder, and despite all my efforts I can't figure out what's wrong.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.