Well, the most reliable way would be to write a parser for the types of files you want to detect, and then just try - if there are no errors, this is clearly the type you tried. However, this is an expensive approach, but it will also ensure that the file is uploaded successfully, since it also checks the rest of the file for semantic reliability.
"" - . , ID3, , MP3. RIFF¼↕☻ WAVEfmt, WAV . , - .