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
Well, does the PHP script work on its own (if you go to the page?)

Also, try removing the header line:
header("Content-Type: image/png");

It should give you a massive output Smile
Also, try this:

<?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 {
            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);
        
    }
?>
New code gives the same output. But I took your suggestion to try and run the PHP directly and get a 500 Internal Server Error. Now to figure out what needs to be installed/rename/etc to get that fixed...one step forward...one step back. Thanks for the lead on what the real issue is Tom...I'll let you know if I get it fixed.
WOOHOOO!!!...Found it...Thank you tons for your pointing me in the right direction Tom.

It was a server side issue that was causing my problem....the php was running with a 755 permission...well when I checked the log I got:

Application.cpp:256: File "/home/*********/banners/random.php" is writeable by group

Ok thats odd I though...did a quick dig on Google and someone had set there to 644 to get a similar issue resolved...ok...tried it and got:

Application.cpp:601: Directory "/home/**************/banners" is writeable by group

Set it down to 755 from 775 and DING DING DING...PHP script runs with direct access...then I ran it on the forums and PERFECT!!!!!!

So to anyone that ever has a similar issue make sure your permission arent set too high...and check your error logs..they can tell you more then you will ever know.

And especially to everyone that posted all the great ideas to get this fixed...my eternal thanks goes to each and everyone of you.
Pages: 1 2