melissam Posted January 3, 2011 Share Posted January 3, 2011 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. Link to comment https://forums.phpfreaks.com/topic/223308-rotatorphp-broke-when-my-host-upgraded-to-php-5/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.