If you are sure you’re only ever working with images, you can check out the getimagesize() exif_imagetype() PHP function, which attempts to return the image mime-type.
If you don’t mind external dependencies, you can also check out the excellent getID3 library which can determine the mime-type of many different file types.
Lastly, you can check out the mime_content_type() function – but it has been deprecated for the Fileinfo PECL extension.