I am looking to veryfy that an MP3 file upload to a server is *actually* an MP3 file
I want to do this by interogating the binary of the file.
I think i have found the file spec for MP3 files here - a little down the page.
I really have no idea where to start with this...could do with a few pointers on what i need to be checking for as i dont fully understand the file spec information, and how i will check this spec using PHP.
Any pointer appreciated.
Thanks
MP3 Binary Interogation
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
getID3 can pull the ID3 information, but having ID3 tags does not make a MP3, unfortunately. You'd need to actually process each packet to ensure conformance to the specification(s) to thoroughly verify it's status. But then again, Pimptastic may not need such stringent verification.
http://www.zend.com/codex.php?id=160&single=1
Also I know there is some code here in the forum someplace for detecting a files type be it's contents...
Also I know there is some code here in the forum someplace for detecting a files type be it's contents...
Well, the file spec says that the header of the MP3 file should look like this
etc. See link in fist post for more information
How would i check that the header bits match that? and would that be a good enough check to prove that it was an MP3 file
Code: Select all
AAAAAAAA AAABBCCD EEEEFFGH IIJJKLMMCode: Select all
Sign(bits) Length (bits) Position Description
A 11 (31-21) Frame sync (all bits set)
B 2 (20,19) MPEG Audio version ID
00 - MPEG Version 2.5
01 - reserved
10 - MPEG Version 2 (ISO/IEC 13818-3)
11 - MPEG Version 1 (ISO/IEC 11172-3)
C 2 (18,17) Layer description
00 - reserved
01 - Layer III
10 - Layer II
11 - Layer I
D 1 (16) Protection bit
0 - Protected by CRC (16bit crc follows header)
1 - Not protectedHow would i check that the header bits match that? and would that be a good enough check to prove that it was an MP3 file