Set the header( content-type: image/<ANY IMG FORMAT>)

I just used this, just indicating it's an image but without specifying image type.

header("Content-type: image");

It seems to be working just fine regardless of file type. I tested with IE, Firefox, Safari and the Android browser.


The solution is to read in the file and decide which kind of image it is and basednd on it send out the appropriate header.

$filename = basename($file);
$file_extension = strtolower(substr(strrchr($filename,"."),1));

switch( $file_extension ) {
    case "gif": $ctype="image/gif"; break;
    case "png": $ctype="image/png"; break;
    case "jpeg":
    case "jpg": $ctype="image/jpeg"; break;
    case "svg": $ctype="image/svg+xml"; break;
    default:
}

header('Content-type: ' . $ctype);