I wanted to write php script so that it can upload mp3 file. but is there a way that i can check that it really is an mp3 but not some text file being renamed to .mp3 extension? I've looked through some example and found this function _checkSongFormat($sSongPath) { $sSongPath = str_replace(" ","%20",$sSongPath); $aMp3Headers = array ( array(0x49, 0x44, 0x33, 0x03), array(0xFF, 0xFB), ); $aSongData = array(); $hF = fopen($sSongPath, 'r'); for ($i = 0; $i < 4; $i++) { $aSongData[$i] = bin2hex(fread($hF, 1)); } fclose($hF); foreach ($aMp3Headers as $aHeader) { $bEqual = true; for ($i = 0; $i < 4; $i++) { if (!isset($aHeader[$i])) { break; } if (dechex($aHeader[$i]) != $aSongData[$i]) { $bEqual = false; break; } } if ($bEqual) { return true; } } return false; } Code (markup): But here's the problem...even a real mp3 file sometimes return as false.
I usually just use this on my audio site: if ($_FILES['audio']['type'] == "audio/mpeg") { // Continue } else { // Error } Code (markup): With the input box name as audio.