MyBB Community Forums

Full Version: Rotating Banner - What am I doing wrong?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I've gone over this what seems like a million times. I'm using the Alphagaming skin on my boards, and I'm trying to get the #mainpic to randomize the banners I have upon page changes or refreshes.

I've tried javascripting it in, but that puts the images above the div table messing everything up.

Then I tried going with a PHP file and it comes up blank. I think the PHP is my best option but I'm not sure what I'm missing...here is the code I'm using...oh and I even made the PHP so it has 755 permissions on the server side.

PHP
<?php 


    $folder = '.'; 


    $extList = array(); 
    $extList['gif'] = 'image/gif'; 
    $extList['jpg'] = 'image/jpeg'; 
    $extList['jpeg'] = 'image/jpeg'; 
    $extList['png'] = 'image/png'; 


$img = null; 


if (substr($folder,-1) != '/') { 
    $folder = $folder.'/'; 
} 


if (isset($_GET['img'])) { 
    $imageInfo = pathinfo($_GET['img']); 
    if ( 
        isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) && 
        file_exists( $folder.$imageInfo['basename'] ) 
) { 
    $img = $folder.$imageInfo['basename']; 
} 
} else { 
    $fileList = array(); 
    $handle = opendir($folder); 
    while ( false !== ( $file = readdir($handle) ) ) { 
        $file_info = pathinfo($file); 
        if ( 
            isset( $extList[ strtolower( $file_info['extension'] ) ] ) 
) { 
            $fileList[] = $file; 
        } 
    } 
    closedir($handle); 


    if (count($fileList) > 0) { 
        $imageNumber = time() % count($fileList); 
        $img = $folder.$fileList[$imageNumber]; 
    } 
} 
if ($img!=null) { 
    $imageInfo = pathinfo($img); 
    $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; 
    header ($contentType); 
    readfile($img); 
} else { 
    if ( function_exists('imagecreate') ) { 
        header ("Content-type: image/png"); 
        $im = @imagecreate (100, 100) 
            or die ("Cannot initialize new GD image stream"); 
        $background_color = imagecolorallocate ($im, 255, 255, 255); 
        $text_color = imagecolorallocate ($im, 0,0,0); 
        imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color); 
        imagepng ($im); 
        imagedestroy($im); 
    } 
} 
?>

And for the #mainpic I'm simply changing the background to: url(/images/alphagaming/banners/random.php)

If anyone has any hint, tricks, thoughts about what I'm doing wrong please let me know.
it appears to be complicated !! this might help ..
While the script is ALOT less complex then the one I listed, it still results in the same issue of the image not displaying properly. My guess is there is some odd piece that I have to be missing...but what...hmmmm
Firstly, are the files there. Secondly, is GD installed on your server correctly?
Your best bet is using HTML. Try this:
http://visitmix.com/labs/glimmer/samples/sequence.html
Hope I helped.
@Tom K
The files are in the same folder in that folder...and checking the PHP Info gives me the following about GD
GD Support 
enabled 

GD Version 
bundled (2.0.34 compatible) 

FreeType Support 
enabled 

FreeType Linkage 
with freetype 

FreeType Version 
2.3.11 

GIF Read Support 
enabled 

GIF Create Support 
enabled 

JPEG Support 
enabled 

libJPEG Version 
6b 

PNG Support 
enabled 

libPNG Version 
1.2.46 

WBMP Support 
enabled 

XPM Support 
enabled 

XBM Support
enabled 

@QuickScope
Glimmer is pretty but not really what I want...but thanks for the suggestion.
Can you do this?

<?php
$rand = rand(1,howevermanyimagesyouhave);
$images[1] = "http://example.com/image.jpg";
$images[2] = "http://example.com/image2.jpg"; //etc


header("Content-Type: image/png");
echo file_get_contents($images[$rand]);
?>
Tried that script as well...and recieve the same blank area where the picture should be. I've even tried using a single string "url(images/alphagaming/banners/mainpic<?php $random = rand(1,n); echo $random; ?>.jpg)" and with the same no image showing results
PHP won't work in CSS files. You need to link to the PHP file in the CSS file.
I figured as much but I've tried just about everything I can even think of...I would have thought that using the "url(images/alphagaming/banners/random.php)" would have been the best most logical choice but that gives me nothing.
Pages: 1 2