Within a form, I need to validate that the file uploaded has an MP3 file format (without using a framework).
I am choosing to validate the upload using the more secure fileinfo method as opposed to a simple file extension check.
The problem I am incurring is that when a legitimate MP3 file is submitted to the form for validation, the MIME type ($mime_type) returned from the MP3 file is application/octet-stream. This is a generic fallback for unknown/generic MIMEs and it doesn't work with a MP3 validation script like so:
// Simplified Version of The Code
// ... File info resource is already opened
if($mime_type == 'audio/mpeg') {
echo '<p>Correct MIME Type</p>';
} else {
echo '<p>Incorrect MIME Type</p>';
}
The code above returns "Incorrect MIME TYPE" for a real MP3 file. This is because the file is portraying as application/octet-stream.