This function determines the correct extension of an image file. Getting types by the file extension is rather insecure, because it can be easily faked.
As an alternative, you can use mime_content_type() to detect the MIME type, even when the file is not an image.
<?php
function get_image_extension($filename)
{
if (function_exists('exif_imagetype'))
{
switch (exif_imagetype($filename))
{
case 1:
return 'gif';
case 2:
return 'jpg';
case 3:
return 'png';
case 4:
return 'swf';
case 5:
return 'psd';
case 6:
return 'bmp';
case 7:
return 'tiff';
case 8:
return 'tiff';
case 9:
return 'jpc';
case 10:
return 'jp2';
case 11:
return 'jpx';
case 12:
return 'jb2';
case 13:
return 'swc';
case 14:
return 'iff';
case 15:
return 'wbmp';
case 16:
return 'xbm';
default:
return false;
}
}
else
return false;
}
?>
If mime_content_type does not work for you, you can use this workaround:
taken from http://www.weberdev.com/mime-content-type
tree2054 using hotmail
04-Nov-2006 02:59