Page 1 of 1

Can PHP read mp3 information?

Posted: Tue Aug 01, 2006 6:15 pm
by toasty2
I'd like to get the name and artist out of a mp3 that is in the script's directory.

Posted: Tue Aug 01, 2006 6:19 pm
by Burrito
yes it can:

search this forum for mp3 or id3 tags. There is a libarary out there that does it and we've discussed it many times.

Posted: Sat Aug 05, 2006 11:43 am
by toasty2
I've looked at a few pages, still no luck. Does anyone know how, or a link to how?

Posted: Sat Aug 05, 2006 12:13 pm
by Burrito

Posted: Sat Aug 05, 2006 1:58 pm
by toasty2
Quicker than you, I found it 2 minutes after that other post I made. I got it to work, but now I am wondering how I can use it for another purpose, and so far it hasn't worked. I am wanting to get the files of a directory, and for all the mp3's, if the artist is a certain artist then to display a list of those songs. Here is the code I have so far, it shows a blank page:

Code: Select all

<?php

$path = "/homepages/21/d155481990/htdocs/server";

$dir_handle = @opendir($path) or die("Unable to open $path");

while ($file = readdir($dir_handle)) 
{
   if($file!="." && $file!=".." && $file!="songlist.php" && $file!="song.php" && $file!="music.html" && $file!="songdevlist.php" && $file!=null)


    $mp3 = $file; //MP3 file to be read


    $filesize = filesize($mp3);
    $file = fopen($mp3, "r");
    fseek($file, -128, SEEK_END);
    
    $tag = fread($file, 3);
    
    
    if($tag == "TAG")
    {
        $data["artist"] = trim(fread($file, 30));    
    }
    else
        die("");
    
    fclose($file);
	strtolower($mp3);
    while(list($key, $value) = each($data))
    {
	
        if ($data["artist"] == 'system of a down')
			{ print("$key: $value<br>\r\n"); }
	
    }
}
//closing the directory
closedir($dir_handle);
?>
And, I have several songs for that artist, and they are in the same directory.