Search code examples
phpexif

Notice: Undefined offset: 0 error


i keep getting the following error and i don't no how to fix it! Help!

Notice: Undefined offset: 0 in C:\public_html\admin\includes\funcs.inc.php on line 51

i do get the warning output error thought...

function getFileExtension($key) {
    $extensions = array(IMAGETYPE_GIF => '.gif', IMAGETYPE_JPEG => '.jpg', IMAGETYPE_PNG => '.png');

    $exifType = exif_imagetype($_FILES['artwork']['tmp_name'][$key]);   
    LINE 51 ---> $ext = $extensions[$exifType];

    return $ext;
}



$ext = getFileExtension($key);

if (!isset($ext)) {
    $warning = 'Error: Unsupported file type (supported images: gif, jpeg, png).';
}

Solution

  • The documentation for exif_imagetype indicates that it returns false when a valid signature is not detected. If you try $extensions[false] you'll get your offset error, so this is probably what is occurring.