Question

After doing some research, I found this link to a "guide" on PHP: ID3 Functions. I'm not quite sure how to go about implementing this into a website so that:

  • Finds all .mp3's in a folder
  • Reads the ID3 tags from the file (Artist, year, etc.)
  • Allows me to put the ID3 tags along with a link to the file on an HTML website

I already have the finding all .mp3's in a folder working, but I'm not sure how to implement the ID3 functions to read from those files.

Was it helpful?

Solution

Easiest way would probably be id3_get_tag($filename, $version).

Just provide a string containing the file path and optionally a ID3 Tag version (leave out if you don't know):

$files = array('/folder/file1.mp3', '/folder/file2.mp3');
$tags = array();
foreach($files as $file) {
    $tags[$file] = id3_get_tag($file);
    // convert genre:
    if(array_key_exists('genre', $tags[$file]) && is_integer($tags[$file]['genre'])
       && $tags[$file]['genre'] >= 0 && $tags[$file]['genre'] <= 147) {
        $tags[$file]['genre'] = id3_get_genre_name($tags[$file]['genre']);
    }
}

$tags will then be an array like this:

['/folder/file1.mp3'] = array('interpret' => 'John Doe', 'title' => 'PHP is cool', 'genre' => 'Techno')
['/folder/file2.mp3'] = array('interpret' => 'Jane Doe', 'title' => 'ASP is low', 'genre' => 'House')

What keys you actually get from this, depends on the ID3 version of each .mp3 file and the actual content (whatever someone wrote into that file).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top