I have the below script for reading the id3 tag for mp3 files. I have checked manually that id3 tags are there in mp3 files but my output always returns for a few files:
MP3 file does not have any ID3 tag!
I am converting these files from ffmpeg. When I run the below code for original files, it shows the id3 tags, but when I run the script for converted files (by ffmpeg), it is not showing any id3 tags . I have downloaded both original and converted files and checked them and found that both files have exactly the same tags but the below code gives the error message anyway.
Here is the code:
<?php
$mp3 = "4.mp3"; //The mp3 file.
$filesize = filesize($mp3);
$file = fopen("4.mp3", "r");
fseek($file, -128, SEEK_END); // It reads the
$tag = fread($file, 3);
if($tag == "TAG")
{
$data["title"] = trim(fread($file, 30));
$data["artist"] = trim(fread($file, 30));
$data["album"] = trim(fread($file, 30));
$data["year"] = trim(fread($file, 4));
$data["genre"] = trim(fread($file, 1));
}
else
die("MP3 file does not have any ID3 tag!");
fclose($file);
while(list($key, $value) = each($data))
{
print("$key: $value<br>\r\n");
}
?>
It requires the correct
id3version. I have solved the problem with this code: