MyBB Community Forums

Full Version: Undefined Index Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys,

I am getting this error in my error_log:

[Fri Oct 24 19:05:56 2014] [error] [client 79.254.117.200] PHP Notice: Undefined index: extension in /var/www/vhosts/marineford.com/httpdocs/images/quickreply/rotate.php on line 177, referer: http://www.marineford.com/cache/themes/theme30/global.css
 

Now the rotate.php is a simple php I downloaded here on mybb.com, which rotates all pictures in a folder for a dynamic logo change e.g.

I used this to put images on the quickreply box:

.quickreply{
    color: black;
    background-image: url(http://marineford.com/images/quickreply/rotate.php); 
 
    background-repeat: no-repeat;
    background-position:right bottom;
}

using <td class="trow1 quickreply" valign="top" width="178px"> in the showthread_quickreply template.

So much for the basics. Now line 177 in the rotate.php is this:

isset( $extList[ strtolower( $imageInfo['extension'] 

Here the whole passage:

$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];
	}
}

1.) So I have no idea what the error "undefined index: extension" means.
2.) I'm using this exact rotate.php on many different images in my forum, not just the quickreply box. But the error only comes for the quickreply box.

Can someone help me? 

Thanks Smile
PHP notices can be mostly ignored.
(2014-10-31, 08:56 AM)StefanT Wrote: [ -> ]PHP notices can be mostly ignored.

Well this may sound nice, but a little more reassuring answer would be appreciated. ^^

What does "undefined index extension" mean? And why do I get this error every 2 seconds?
It would appear that either $imageInfo['extension'] or $file_info['extension'] does not have a value for 'extension.'
I'm not 100% positive, but it might be that you are trying to do a function in an array key.
(2014-10-31, 01:29 PM)HolyPhoenix Wrote: [ -> ]It would appear that either $imageInfo['extension'] or $file_info['extension'] does not have a value for 'extension.'

(2014-10-31, 05:11 PM)dragonexpert Wrote: [ -> ]I'm not 100% positive, but it might be that you are trying to do a function in an array key.

And what would I have to do to solve this issue?
I hate to give you all the answers, you should at least try to figure it out on your own.

But..

If it is what I said then
$img = null;

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

if (isset($_GET['img'])) {
    $imageInfo = pathinfo($_GET['img']);
    if (
		isset( $imageInfo['extension'] ) &&
        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( $file_info['extension'] ) &&
            isset( $extList[ strtolower( $file_info['extension'] ) ] )
        ) {
            $fileList[] = $file;
        }
    }
    closedir($handle);

    if (count($fileList) > 0) {
        $imageNumber = time() % count($fileList);
        $img = $folder.$fileList[$imageNumber];
    }
} 

I'll let dragonexpert give you the solution if it is what he says, though it wouldn't be too hard to do since you'd just have to move your strtolower outside of the isset check.